Info

This question is closed. Reopen it to edit or answer.

How can I eliminate a row and then make it appears again?

1 view (last 30 days)
Hi, I have a matrix and I want to eliminate two rows, try the rank of the matrix and then if the rank is not the one that I need, make the rows appear again to keep eliminating and testing. Eliminate R1-R2, try the rank, if it is not match, have the original matrix again, eliminate R2-R3, try the rank...until I get the rank that I need. Thank you so much
  1 Comment
Stephen23
Stephen23 on 11 Feb 2016
The simple answer is don't change your matrix. Instead you should keep your original matrix unchanged, and simply select subsets of it to perform your calculations on. This is much more robust way to program!
This is usually considered good programing style: keep data changes to a minimum, and use indexing to access the bits that you need.

Answers (1)

Andrei Bobrov
Andrei Bobrov on 11 Feb 2016
Edited: Andrei Bobrov on 11 Feb 2016
Let A - your array and b - value of your rank.
for ii = 1:size(A,1)-1
rnk = rank(A([1:ii-1,ii+2:end],:));
if rnk == b
out = A([1:ii-1,ii+2:end],:);
break
end
end

Community Treasure Hunt

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

Start Hunting!