I have a cell such as
C={};
C{1,1}='A';
C{1,2}='B';
C{1,3}='C';
C{2,1}=[1 0 1;0 0 1;2 1 -1];
C{2,2}=[1 2 -1;-1 0 1;0 1 -1];
C{2,3}=[1 0 -1;-1 0 1;-1 1 -1];
C{3,1}=5/9;
C{3,2}=2/9;
C{3,3}=-1/9;
C =
3×3 cell array
{'A' } {'B' } {'C' }
{3×3 double} {3×3 double} {3×3 double}
{[ 0.5556]} {[ 0.2222]} {[ -0.1111]}
I want to remove a column which have the value -1<=x>=1 in all of the elements in the matrix at the second row. Such that
C =
3×2 cell array
{'A' } {'B' }
{3×3 double} {3×3 double}
{[ 0.5556]} {[ 0.2222]}

4 件のコメント

jonas
jonas 2018 年 8 月 13 日
編集済み: jonas 2018 年 8 月 13 日
Unclear to me. Do the 3x3 arrays change? Can you highlight the values between -1 and 1 you are referring to?
KSSV
KSSV 2018 年 8 月 13 日
C{2,2} also has -1<=x>=1.....isn't it?
Mohamad Agung Prawira Negara
Mohamad Agung Prawira Negara 2018 年 8 月 13 日
編集済み: Mohamad Agung Prawira Negara 2018 年 8 月 13 日
What I mean is that all elements of 3x3 arrays (all 9 elements is -1<=x<=1). As for C{2,2}, it has 2 in one of the elements.
jonas
jonas 2018 年 8 月 13 日
編集済み: jonas 2018 年 8 月 13 日
So what you mean is that you want to keep columns where at least one element (out of 9) lies outside of the specified bounds?

サインインしてコメントする。

 採用された回答

jonas
jonas 2018 年 8 月 13 日
編集済み: jonas 2018 年 8 月 13 日

0 投票

Try this
B=cellfun(@(x) sum(sum(abs(x)>1)),C(2,:),'uniformoutput',false)
B=cell2mat(B);
C(:,B<1)=[]
C =
3×2 cell array
{'A' } {'B' }
{3×3 double} {3×3 double}
{[ 0.5556]} {[ 0.2222]}

2 件のコメント

Mohamad Agung Prawira Negara
Mohamad Agung Prawira Negara 2018 年 8 月 13 日
Thanks, this one works for me
jonas
jonas 2018 年 8 月 13 日
No problem! It only works for symmetric bounds. Just so you know.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Structures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by