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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by