Logical Indexing with zero and one. Getting only the change from 0 to 1 and from 1 to 0.
Afficher commentaires plus anciens
Is there any way to from matrix A to matrix B without using find?
A= B=
0 0
0 0
0 0
0 0
0 0
0 0
1 1
1 0
1 0
1 0
1 1
0 0
0 0
0 0
0 0
0 0
Thank you.
Réponses (2)
Andrei Bobrov
le 12 Juin 2013
Modifié(e) : Andrei Bobrov
le 12 Juin 2013
B = [0;diff(A)==1] + flipud([0;diff(A(end:-1:1))==1]);
B = [false;diff(A)==1] | flipud([false;diff(A(end:-1:1))==1]); % logical
1 commentaire
Giorgos Papakonstantinou
le 12 Juin 2013
Giorgos Papakonstantinou
le 12 Juin 2013
Modifié(e) : Giorgos Papakonstantinou
le 12 Juin 2013
1 commentaire
Image Analyst
le 12 Juin 2013
I have no idea what this is about. This code has no relation to your original question whatsoever. But if it does what you want, go for it. No one cares about efficiency when you're only dealing with 315 elements. What would you save - a nanosecond? Now if you had 315 million elements, then it would be a concern.
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!