フィルターのクリア

Getting the Indices of an Array with conditions

1 回表示 (過去 30 日間)
ARN
ARN 2018 年 9 月 12 日
コメント済み: ARN 2018 年 9 月 12 日
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
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
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.

サインインしてコメントする。

採用された回答

Jan
Jan 2018 年 9 月 12 日
編集済み: Jan 2018 年 9 月 12 日
A bold guess:
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 ];
Ap = [0, A, 0]; % Padding to care for leading and trailing 1s
ini = strfind(Ap, [0,1]);
fin = strfind(Ap, [1,0]);
B = reshape([ini-1; ini; fin-1], 1, []);
  1 件のコメント
ARN
ARN 2018 年 9 月 12 日
I am sorry, i couldn't explain properly. This works Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by