Select matrix rows based on criteria

조회 수: 17 (최근 30일)
Julie
Julie 2011년 10월 3일
I have a 1000 rows by 100 column matrix. i) wish to select those rows which meet a criteria, and then use this to select the equivalent position from a second column vector. I tried to produce a column vector where if any element i n a row met or exceeded the criteria then I would get a 1 (or 0 if not). Then i planned to use this 'mask' to select from the second vector.# My problems:
criteria = >10.6 mask=(data(:))>=10.6;
returns an empty matrix. What am I missing? is there a simple way.[The second column vector could be included in the original data but must not be part of the elements evaluated against the criteria] Thanks in advance

채택된 답변

Matt Tearle
Matt Tearle 2011년 10월 3일
I can't quite work out the code (maybe the formatting is confusing me), but it sounds like what you're trying to do is this:
A = magic(4)
y = (14:17)'
threshold = 13;
idx = any(A > threshold,2);
y(idx)
This selects the rows of A that contain any value greater than 13, then extracts those rows of the 4-element column vector y.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by