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 ExchangeOperators and Elementary Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by