Reputation: 363
I want to make an array 15*15 and fill them with these code and I want to find max of a row of it. I wrote this codes in MATLAB to make an array:
a = zeros (15) - inf;
for i=1:15
k2=4;
l2=1;
k=floor((i-1)/3);
l=mod((i-1),3);
f=false;
if (k==k2 && abs(l2-l)==1)
f=true;
end
if(l==l2 && k2-k==1)
f=true;
end
if(k2-k==1 && abs(l2-l)==1)
f=true;
end
if (f)
a(i,14)=100;
end
end
max=200;
for i=1:15
if(find(2,i) < max)
max=i;
end
end
max=0
when I wrote these codes to find maximum index in 2nd row of array this error shown:
b=a(2,:)
b =
1 -Inf 1 1 1 1 -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
>> [~,index]=max(b)
??? Indexing cannot yield multiple results.
Upvotes: 0
Views: 2002
Reputation: 19870
You have variable max and trying to use function max.
It's a good practice to check for existing names with exist var_name
or which var_name
command.
Rename your variable max
in the code and remove it from the workspace with clear max
.
Upvotes: 3