Looping over column and returning values where conditions are met
조회 수: 9 (최근 30일)
이전 댓글 표시
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).
댓글 수: 3
답변 (1개)
James Tursa
2020년 4월 5일
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
James Tursa
2020년 4월 5일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!