vendredi 24 avril 2015

Delete rows in a table using a for-loop

My data is formatted as a table in Matlab: T =

  J K L M N O
  121 1 1 a1 3b 1.72
  121 2 1 2c 4d 1.43
  0 3 1 e3 5f nan
  299 4 1 g4 h5 1.64
  299 1 2 4i 4j 1.48
  0 2 2 6k nan 2.33
  0 3 2 m7 8n nan
  455 4 1 i4 j5 3.24
  4 2 o8 p0 1.92

I would like to delete every row where I have a zero or 299 in columns J

I tried

numberrows1 = size(T,1);
for i=1:numberrows1
    if T{i,1} == 8.4
        T(i,:) = [];
    end

     if T{i,1} == 0.0
         T(i,:) = [];
     end
end

But I get always an error:

Row index exceeds table dimensions.

What do I wrong?

Aucun commentaire:

Enregistrer un commentaire