Looping over column and returning values where conditions are met
12 views (last 30 days)
Show older comments
I want to loop over a first column (which is column numbers) and return the values when the conditions are met for the next 4 columns. I already have a loop that finds the count of columns that meet conditions but I want it to return the first column values. For example in the image below the highlighted rows are the conditions that are satified and I want to find and reutrn the row numbers (3,5,6 and 9).
Answers (1)
James Tursa
on 5 Apr 2020
In general, perform find( ) on the condition you want. E.g.,
find(matrix(:,4)>80)
would return the row numbers where the 4th column is greater than 80.
4 Comments
James Tursa
on 5 Apr 2020
Sure. If your loop index k is looping over the rows, then you could test within the loop
if( matrix(k,4)>80 & matrix(k,3)<350 )
% do something
end
See Also
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!