arrays - MATLAB: removing some of the elements of a matrix -
Text after "
I have a matrix that looks like:
one = [1 5 2 10 3 12 4 25 5 8] Suppose I want to remove those rows containing elements which are larger than 10 . I am trying to use a loop and just read the matrix and use <= p> for ij = 2: jj = 2 if a (ii, jj) & gt; 10a (ii, 2) = []; End of End The problem is, I get errors about the size of the matrix. Since a line is wiped, the size of the matrix decreases and I know that I have to set the size (a) = size (a) -1 , but it does not work. Any help is appreciated!
After
When you can not remove any elements using subcript marking, then your error is here:
a (i, 2) = []; You have two options, either remove the whole line:
A (i, :) = []; Otherwise remove linearise your metrics and single elements (but then you will not be able to recover the original size: b = for numel (A): - 1: 1 then (ii)> 10a (ii) = []; end end But for this, using a loop is unnecessary and perhaps You can do this by using such a rational indexing:
A (any ('A'> 10), :) = []; < / Pre> Try removing the entire line or just another element: < / P>
A (A & gt; 10) = [] But then you will see that you end up with a line vector (drawn) result With
Comments
Post a Comment