![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/366310/image.png)
How to store the indexes of the values which satisfies the given condition while running a loop. The condition is satisfied many times but at the end only i only get the index of last condition when value was satisfied.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
function indices=Saddle(M)
[a,b]=size(M);
P=max(M,[],2);
Q=min(M);
for i=1:a
for j =1:b
if P(i,1)==Q(1,j)%my condition which needs to be satisfied
F(i)=i; F1(j)=j;%value of all the indexes.i.e i or j must be stored here as an array but I am getting only one value
end
end
end
if F==0
indices=[];
else
indices=[F;F1];
end
0 comentarios
Respuestas (1)
Sudhakar Shinde
el 25 de Sept. de 2020
Hopefully you are looking for the:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/366310/image.png)
%Code is here. You can change F(i)=i; F1(j)=j; to indices{end+1} = [i,j];
function indices=Saddle(M)
[a,b]=size(M);
P=max(M,[],2);
Q=min(M);
indices = {};
for i=1:a
for j =1:b
if P(i,1)==Q(1,j)%my condition which needs to be satisfied
indices{end+1} = [i,j];
end
end
end
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!