Matlab filter columns of array based on value in row

21 ビュー (過去 30 日間)
Nobutaka Kim
Nobutaka Kim 2022 年 2 月 7 日
回答済み: Arif Hoq 2022 年 2 月 7 日
I have a 3 x 3000 array with x, y, z as the rows.
I want a new array from filtering the above if z == 3.
I tried
```
task3_xy = xy_arr(~ismember(xy_arr(3, :), [3]),:);
```
but it's telling me
The logical indices in position 1 contain a true value outside of
the array bounds.
How else can I do this?

採用された回答

Arif Hoq
Arif Hoq 2022 年 2 月 7 日
use 'find' function to look up the value which is equal to 3 in 'z'
x=randi(100,3,3000);
y=randi(80,3,3000);
z=randi(50,3,3000)
z = 3×3000
35 8 45 3 21 6 11 1 25 14 2 45 43 47 29 20 38 46 48 21 9 24 50 30 24 17 35 9 16 5 4 31 34 37 50 31 38 47 22 12 3 9 6 25 12 19 16 6 30 40 31 42 19 21 24 37 3 43 3 21 16 48 19 3 32 24 27 10 37 7 36 26 13 10 25 40 43 50 2 46 22 3 50 43 46 1 43 14 9 9
Idx_New_array=find(z==3) % index value of z whihc is equal to 0
Idx_New_array = 179×1
10 12 32 66 80 86 156 194 270 349
if you want to find the row and column
[row col]=find(z==3)
row = 179×1
1 3 2 3 2 2 3 2 3 1
col = 179×1
4 4 11 22 27 29 52 65 90 117
is that your expectation or you want to replace the index value of z ?

その他の回答 (1 件)

Nobutaka Kim
Nobutaka Kim 2022 年 2 月 7 日
I can do it in a multi-step process
```
xy_arr = [x; y; task_num];
xy_logical_arr = (xy_arr(3, :)==3);
job_xy = xy_arr(:, xy_logical_arr);
```

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by