Get both values and indices

2 ビュー (過去 30 日間)
Md. Al-Imran Abir
Md. Al-Imran Abir 2022 年 12 月 3 日
回答済み: Dyuman Joshi 2022 年 12 月 3 日
I am trying to get the indices and values from a vector based on a condition. I used find for that but the values it returning are logical values. How can I get actual values? An example is:
X = [4; 5; 1; 0; -7; 3; 0; 1; -4];
[row, ~, val] = find(X>0 & X<6)
row = 5×1
1 2 3 6 8
val = 5×1 logical array
1 1 1 1 1
I want val to have 4 5 1 3 1

採用された回答

Dyuman Joshi
Dyuman Joshi 2022 年 12 月 3 日
X = [4; 5; 1; 0; -7; 3; 0; 1; -4];
row = find(X>0 & X<6)
row = 5×1
1 2 3 6 8
val = X(row)
val = 5×1
4 5 1 3 1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by