Hello there, I have a short question, as for some reason a for loop doesn't function.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
RT is a matrix and krit_out1 is a vector. There is no error message, but the loop is stuck in the first row of the matrix and I don't find the reason.. Can someone help me?
for i = 1:50
RT(RT(:,i)> krit_out1(i)) = NaN;
end
1 Kommentar
Stephen23
am 24 Okt. 2017
Loops are not required to solve this. See Jan Simon's answer for a simple and efficient solution.
Akzeptierte Antwort
Birdman
am 23 Okt. 2017
RT=ones(50,50);krit_out1=zeros(50,1);
for i=1:50
for j=1:50
if(RT(j,i)>krit_out1(j))
RT(j,i)=NaN;
end
end
end
Try this.
2 Kommentare
Jan
am 23 Okt. 2017
krit_out1( i ) instead of j.
The vectorization of such loops is not only nice and processed efficiently, but without indices, there are less chances for typos.
Weitere Antworten (2)
Ray
am 23 Okt. 2017
Try the following. It looks like you intend to operate on the ith column using the ith element of a vector called krit_out1:
for i = 1:50
RT(RT(:,i)> krit_out1(i) ,i) = NaN;
end
4 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!