How to find corresponding indices?

1 次查看(过去 30 天)
Kendal
Kendal 2022-11-9
回答: Voss 2022-11-9
Good Day,
I have a dataset I am working (891 rows,12 columns) with and have already sorted one column with zeros and ones (Logical). I would now like to pull data from 2 other columns (number and text) where the ones are located (neglecting the zeros). How can I write this in matlab?
TIA!

回答(1 个)

Voss
Voss 2022-11-9
% some data
data = [0 10]+(1:10).'
data = 10×2
1 11 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 20
% whether to get each row:
rows_to_get = [false; false; true; true; false; false; false; true; true; false]
rows_to_get = 10×1 logical array
0 0 1 1 0 0 0 1 1 0
% final result:
result = data(rows_to_get,:)
result = 4×2
3 13 4 14 8 18 9 19

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by