Removing a specific row from a matrix

2 ビュー (過去 30 日間)
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis 2018 年 6 月 15 日
Hi all,
I would like to remove a row from a matrix, however I cannot seem to be able to do it. Here is an example:
a = [1 2 ; 3 4 ; 5 6 ; 7 8]; %matrix
b = [3 4] ; %vector to remove
a( a==b) = [] ; %removing the vector
This seems to be working, however the matrix 'a' is returned as:
a = [1 5 7 2 6 8] ;
The desired format would be:
a = [1 2 ; 5 6 ; 7 8] ;
How would can I get that?
Thanks for your help in advance,
KMT.

採用された回答

Walter Roberson
Walter Roberson 2018 年 6 月 15 日
a = reshape(a, [], 2);
However, better could would be
a( ismember(a, b, 'rows'), :) = [];
  1 件のコメント
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis 2018 年 6 月 15 日
Works as expected, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by