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.
-Infjust by subtractinginffrom the zeros matrix so you don't need the loops. I have edited your code to reflect this.zeros (15,15) - inf;does not make sense at all when the created array is not assigned to a variable.