How to find position of array
Afficher commentaires plus anciens
For example i have data like this [11111100001111]
Now i need to find out the position of first 1 and last 1 of first group of 1s and then position of first 1 and last 1 of second group of 1s. How do i do this??
i have used' find' to find the position of all 1s but i dont want all...instead 1 want only the first and last position of groupof 1s
2 commentaires
madhan ravi
le 17 Juin 2019
[1 0 1 1 0 0 0 0 1 1 1 1] - the result would be?
Wind flower
le 20 Juin 2019
Réponse acceptée
Plus de réponses (1)
madhan ravi
le 17 Juin 2019
Simpler without any conversions:
s=[1 0 1 1 0 0 0 0 1 1 1 1]; % example data
x=s~=0;
Start = strfind([0,x],[0 1])
End = strfind([x,0],[1 0])
3 commentaires
madhan ravi
le 17 Juin 2019
s = 11111100001111; % if your data is indeed like below then
m = floor(log10(s));
D = mod(floor(s ./ 10 .^ (m:-1:0)), 10);
x=D~=0;
Start = strfind([0,x],[0 1])
End = strfind([x,0],[1 0])
Rik
le 17 Juin 2019
Note that using numeric arrays as inputs to strfind is currently undocumented (and it even returns an error in GNU Octave). It would be nice if Mathworks changed the documentation. It would be even better if they extended this function to work on arrays of any object type.
Wind flower
le 20 Juin 2019
Modifié(e) : madhan ravi
le 20 Juin 2019
Catégories
En savoir plus sur Data Type Conversion 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!