How to extract the first and last position for each ones series ?
1 次查看(过去 30 天)
显示 更早的评论
For example
How to extract the first and last position for each ones series ?
X= [0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 ]
%result
y =
3 5
7 8
10 12
15 15
Thanks
1 个评论
Cedric
2013-1-23
If it is for indexing something else afterwards, you can use that almost directly for logical indexing; you just have to typecast it to logical. E.g.
>> X = [0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 ] ;
>> a = 1:15 ;
>> a(logical(X))
ans =
3 4 5 7 8 10 11 12 15
采纳的回答
更多回答(3 个)
Azzi Abdelmalek
2013-1-23
You can use
x= [ 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 ]
y=[x(1) diff(x)] % to find the first column
x1=fliplr(x) % to find the second column by the first method, just by
% reversing x
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!