フィルターのクリア

delete rows in Matrix 'A' with same values 'c' in column 'b'

1 回表示 (過去 30 日間)
Paul
Paul 2012 年 12 月 4 日
There is a Matrix of variating size, in this case for example 10x4:
A =
|12 1 1 4|
|16 2 1 6|
|8 3 2 6|
|15 4 2 1|
|17 5 2 2|
|1 6 2 3|
|14 7 3 4|
|13 8 3 7|
|12 9 4 6|
|11 10 5 7|
Now I have a look on the 3rd row (because of b=3). The given vector c=[2,4] now says to me which rows to delete in 'A'. If there is a '2' or a '4' in line b=3, then delete this row like this:
A =
|12 1 1 4|
|16 2 1 6|
|14 7 3 4|
|13 8 3 7|
|11 10 5 7|
It must be quite easy, I guess.

採用された回答

Honglei Chen
Honglei Chen 2012 年 12 月 4 日
編集済み: Honglei Chen 2012 年 12 月 4 日
Here is an example:
b = 3;
c = [2 4];
A = perms(1:4);
A(ismember(A(:,b),c),:)=[]

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 4 日
編集済み: Azzi Abdelmalek 2012 年 12 月 4 日
b=3;
c=[2 4]
idx=any(ismember(A(b,:),c));
if idx==1
A(b,:)=[]
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by