Effacer les filtres
Effacer les filtres

Extract Values from Matrix row

4 vues (au cours des 30 derniers jours)
Denis Muhra
Denis Muhra le 12 Avr 2021
Commenté : Adam Danz le 12 Avr 2021
I have a Dataset padded with -500 so the row length of the matrix stays the same. Now I want to extract an array from a row containing only the values that aren't -500.
A = [2,1,2,3,4,-500,-500,-500 ; 2,3,4,5,-500,-500,-500,-500]
i've tried this but it gives me only the boolean answer
A1 = A(1,:) > -500 -> A1 = [1,1,1,1,1,0,0,0]
what i want would be A1 = [2,1,2,3,4]
Can anybody help me?
Thanks in Advance

Réponse acceptée

David Fletcher
David Fletcher le 12 Avr 2021
You can use the logical vector to index the main array i.e
  1 commentaire
Adam Danz
Adam Danz le 12 Avr 2021
Better yet, combine them into 1 line,
A1 = A(1,A(1,:)~=-500)

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Matrix Indexing dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by