delete value from double class by using logical class

1 回表示 (過去 30 日間)
ha ha
ha ha 2018 年 3 月 20 日
編集済み: ha ha 2018 年 3 月 20 日
Let's say:
A : 2x7 double class
A=[ 1 2 3 4 5 6 7; 8 9 1 2 3 4 5] ;
A=[ 1 2 3 4 5 6 7
8 9 1 2 3 4 5 ]
B: 2x7 logical class:
B=boolean( [1 0 0 0 0 0 1;1 0 1 1 1 1 1] );
B={ 1 0 0 0 0 0 1
1 0 1 1 1 1 1 }
How to find the matrix C (double class)as follow result from A & B:
C=[ 1 7
8 1 2 3 4 5 ]
C=[1 7; 8 1 2 3 4 5] ????
  2 件のコメント
Rik
Rik 2018 年 3 月 20 日
You can't. Arrays in Matlab are always rectangular.
ha ha
ha ha 2018 年 3 月 20 日
編集済み: ha ha 2018 年 3 月 20 日
thank @Rik Wisselink

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

採用された回答

Jan
Jan 2018 年 3 月 20 日
編集済み: Jan 2018 年 3 月 20 日
As said already: Matrices must be rectangular. But you can use a cell array:
A = [ 1 2 3 4 5 6 7; ...
8 9 1 2 3 4 5];
B = logical([ 1 0 0 0 0 0 1; ...
1 0 1 1 1 1 1]);
n = size(A, 1);
C = cell(n, 1);
for k = 1:n
C{k} = A(k, B(k, :));
end
Then:
C = {[1 7]; ...
[8 1 2 3 4 5]}

その他の回答 (1 件)

Birdman
Birdman 2018 年 3 月 20 日
Addition to Rik's comment, you should use cell array for this type of problems:
idx=A&~B;
C=mat2cell(A,ones(1,size(A,1)),ones(1,size(A,2)));
C(idx)={[]}

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by