Hello there, I have a short question, as for some reason a for loop doesn't function.
Show older comments
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 Comment
Stephen23
on 24 Oct 2017
Loops are not required to solve this. See Jan Simon's answer for a simple and efficient solution.
Accepted Answer
More Answers (2)
Or without a loop:
RT(RT > krit_out1(:).') = NaN; % >= R2016b: Auto-Expanding
For older Matlab versions:
index = bsxfun(@gt, RT, krit_out1(:).'); % [EDITED]
RT(index) = NaN;
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!