Getting the Indices of an Array with conditions
조회 수: 1 (최근 30일)
이전 댓글 표시
i have a program in which i have a matrix (Let's say A) of 0's and 1's. The occurance of 0's and 1's are random I want to get the indeces information for example
A1= [- - - - - - - - - 15:30:00 15:30:01 15:30:02 15:30:03 15:30:04 15:30:05 15:30:06 15:30:07 - - - - 15:30:12 15:30:13 15:30:14 15:30:15 15:30:16 15:30:17 - - - - - - 15:30:24 15:30:25 15:30:26 15:30:27 - - 15:30:30 15:30:31 - - ];
A= [0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 ];
% i want the result vector to be like
B=[9 10 17 21 22 27 33 .....]
Conditions: 1. for all the zeros only one zero 2. for ones Starting and ending one
Or end result
B1= [0 15:30:00 15:30:07 0 15:30:12 15:30:17 0 15:30:24 15:30:27 0 15:30:30 15:30:31 0]
댓글 수: 3
Jan
2018년 9월 12일
Please post working Matlab code. I cannot guess reliably, what
A1= [- - - - - - - - - 15:30:00 15:30:01 ...
is. A cell string? A string? A timeseries object, where - means a NaT?
The explanation "1. for all the zeros only one zero 2. for ones Starting and ending one" is not clear to me. Can you elaborate it a little bit? You mention two different wanted outputs:
B=[9 10 17 21 22 27 33 .....]
B1= [0 15:30:00 15:30:07 0 15:30:12 ...
What do you want exactly?
Rik
2018년 9월 12일
It looks like you should have a vector with true for each valid position and false for non-valid positions. Then you can use diff to find the alternation points and find the indices for your output.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!