Filter data of cell array

23 次查看(过去 30 天)
Hi all,
I'm looking for a way to effectively filter data (in a cell array) similar to the filter option in Microsoft Excel. In the following I'll quickly describe a simple example with only 2 columns to clarify my problem:
The cell array consists of 2 columns and 4 rows where the to colums represent parameters and the rows different datasets. I now want to find the line number(s) of the row where column one is 1 and column 2 is A.
[1] [A]
[1] [B]
[0] [A]
[1] [A]
I can only think of using for loops for each column to solve this problem. However, in the real problem there are many more than 2 columns and I therefore seek to tackle the problem more efficiently. Do you have an idea how to start?
Thanks in advance,
bearli

采纳的回答

Walter Roberson
Walter Roberson 2011-11-26
rows = find( arrayfun(@(RIDX) YourCell{RIDX,1} == 1 && strcmp(YourCell{RIDX,2}, 'A'), 1:size(YourCell,1)) );
If all of your values are numeric and all of your cells are scalar, then probably easier would be
t = cell2mat(YourCell);
rows = find( t(:,1) == 1 & t(:,2) == A );

更多回答(0 个)

类别

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