Select values in the matrix based on the condition

30 ビュー (過去 30 日間)
Turbulence Analysis
Turbulence Analysis 2022 年 6 月 29 日
コメント済み: Steven Lord 2022 年 6 月 29 日
Hi,
I have two matrix A and B of 94349 x 1.
Here the values in the matrix A are range from 0 to 1. First, I have to identify row numbers in the matrix A that got values only in the range of 0.05 to 0.06. Then I have to read values from matrix B that pertains to only the preselected rows from step 1.

採用された回答

NIVEDITA MAJEE
NIVEDITA MAJEE 2022 年 6 月 29 日
編集済み: NIVEDITA MAJEE 2022 年 6 月 29 日
Hi,
You could do the following:
filtered_idx = find((A>=0.05 & A<=0.06)) %this will store the indexes from the matrix A which have values between 0.05 and 0.06
filtered_B = B(filtered_idx) %this will store the values corresponding to the indexes stored in filtered_idx
Hope this helps!
  1 件のコメント
Steven Lord
Steven Lord 2022 年 6 月 29 日
You don't care where the items in the desired range are located, all you care is that you can select them. So you don't need find.
x = 1:10;
logicalMask = (4 <= x) & (x <= 7)
logicalMask = 1×10 logical array
0 0 0 1 1 1 1 0 0 0
linearIndices = find(logicalMask)
linearIndices = 1×4
4 5 6 7
You can use either the logical mask or the linear indices to obtain the values from x. But you can see that calling find is a second step beyond generating the logical mask, so if you don't actually need the linear indices why compute them?
x(logicalMask)
ans = 1×4
4 5 6 7
x(linearIndices)
ans = 1×4
4 5 6 7

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by