Deleting a row y from a matrix

2 次查看(过去 30 天)
If I have a matrix A and I want to delete all the rows, y, in A such that y=[1 2 3];
Ex:
A=[ 1 2 3; 4 5 6; 7 8 9; 1 2 3]; y=[1 2 3];
I want to remove all the y vectors from A so that I have:
A=[4 5 6; 7 8 9];

回答(1 个)

JESUS DAVID ARIZA ROYETH
编辑:JESUS DAVID ARIZA ROYETH 2020-2-17
A(all(A==y,2),:)=[]
edit previous versions:
A(all(A==repmat(y,size(A,1),1),2),:)=[]
  6 个评论
Cantor Set
Cantor Set 2020-2-17
Error using ==
Matrix dimensions must agree.
JESUS DAVID ARIZA ROYETH
try now:
A=[ 1 2 3; 4 5 6; 7 8 9; 1 2 3]; y=[1 2 3];
A(all(A==repmat(y,size(A,1),1),2),:)=[]

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by