How do I filter data of a cell based on a column value?

15 ビュー (過去 30 日間)
Joel Abrahams
Joel Abrahams 2017 年 7 月 16 日
回答済み: Akira Agata 2017 年 7 月 16 日
Say I have a 100x100 cell.
I want to get all the rows where the 9th column is equal to 3, and all the rows where this isn't the case. These would be stored in two separate variables.
How would I do this?

採用された回答

Akira Agata
Akira Agata 2017 年 7 月 16 日
I think the code will be like this:
% 100x100 sample cell array
C = num2cell(randi(10,100,100));
% Rows where the 9th column is equal to 3
idx = cellfun(@(x) isequal(x,3), C(:,9));
% Extract the target rows
C1 = C(idx,:);
% Others
C2 = C(~idx,:);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by