Hello,
I have an issue filtering a cell matrix that is created from a standard array. When I create the cell matrix outright (not converting a standard matrix), my filtering works exactly as intended. For example, when I try to filter a cell matrix created by the following method:
K={1 32 5 6
4 12 6 8
09 3 6 1}
And filter the third column for each row containing a 6 via:
p=K([K{:,3}]==6,:)
I get exactly what I want which are the rows that correspond to the filtered third column of the original K cell matrix. When I create a cell matrix from a standard matrix though and try to filter the same way I get an error. For example, this code:
A=[1 34 2; 6 4 2; 9 1 0]
B={A}
C=B([B{:,3}]==2,:)
Gives the following error which corresponds to the line defining C:
Index exceeds matrix dimensions.
I don't understand what the difference between my first and second filtering methods are. How would I filter the cell matrix B exactly like I filtered K?
Thanks in advance.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 7일
편집: Azzi Abdelmalek 2015년 7월 7일

0 개 추천

A=[1 34 2; 6 4 2; 9 1 0]
B=num2cell(A)
C=B([B{:,3}]==2,:)
If you write B={A}, B is a 1x1 cell array. I think what you are looking for is num2cell(A) which is 3x3 cell array

댓글 수: 1

Patrick Comiskey
Patrick Comiskey 2015년 7월 7일
This works perfectly! Thank you for your quick response Azzi.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by