Filter data of cell array
조회 수: 25 (최근 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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!