How to find position of array
이전 댓글 표시
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
madhan ravi
2019년 6월 17일
[1 0 1 1 0 0 0 0 1 1 1 1] - the result would be?
Wind flower
2019년 6월 20일
채택된 답변
추가 답변 (1개)
madhan ravi
2019년 6월 17일
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
madhan ravi
2019년 6월 17일
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
2019년 6월 17일
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
2019년 6월 20일
편집: madhan ravi
2019년 6월 20일
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!