Filter data of cell array

23 views (last 30 days)
Bearli Ubuku
Bearli Ubuku on 26 Nov 2011
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

Accepted Answer

Walter Roberson
Walter Roberson on 26 Nov 2011
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 );

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!