MATLAB Answers

JL
0

emptying each row of a matrix in a loop

Asked by JL
on 22 Aug 2019 at 19:38
Latest activity Commented on by JL
on 22 Aug 2019 at 20:53
Is there a way to empty each row of a matrix in a loop? For example
a = [1 2;
1 3;
1 5;
1 7;
1 8;];
first loop
a = [
1 3;
1 5;
1 7;
1 8;];
second loop
a = [1 2;
1 5;
1 7;
1 8;];
and so on until the last loop
a = [1 2
1 3;
1 5;
1 7;
];

  0 Comments

Sign in to comment.

1 Answer

Answer by Matt J
on 22 Aug 2019 at 19:52
Edited by Matt J
on 22 Aug 2019 at 19:54
 Accepted Answer

a0=a;
for i=1:size(a,1)
a=a0;
a(i,:)=[],
end

  4 Comments

Show 1 older comment
JL
on 22 Aug 2019 at 20:01
Hi Matt, how do i include the first one in the loop before one row is emptied at each loop?
a = [1 2;
1 3;
1 5;
1 7;
1 8;];
Matt J
on 22 Aug 2019 at 20:45
a0 is the original matrix. It is available throughout the loop.

Sign in to comment.