MATLAB Answers

emptying each row of a matrix in a loop

1 view (last 30 days)
JL
JL on 22 Aug 2019
Commented: JL on 22 Aug 2019
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.

Accepted Answer

Matt J
Matt J on 22 Aug 2019
Edited: Matt J on 22 Aug 2019
a0=a;
for i=1:size(a,1)
a=a0;
a(i,:)=[],
end

  4 Comments

Show 1 older comment
JL
JL on 22 Aug 2019
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
Matt J on 22 Aug 2019
a0 is the original matrix. It is available throughout the loop.

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by