How to count the time interval at which a particular number occurs in matrix
2 ビュー (過去 30 日間)
古いコメントを表示
suppose I have a matrix let it be 1x20 where I have a strange number 999, which occurs in the following sequence a=[1,2,999,999,3,45,5,999,999,999,999,6,5,8,999,5,67,8,999,7] so i want number of time 999 occurs must be equal to 4 but i am getting the result as a number of time 999 occurs = 8 please help me in this matter.
1 件のコメント
Ganesh Hegade
2017 年 6 月 26 日
The example matrix has '999' 8 times. So the answer is correct. Exactly what are you trying to achieve ?
回答 (2 件)
Andrei Bobrov
2017 年 6 月 26 日
編集済み: Andrei Bobrov
2017 年 6 月 26 日
out = a(diff([0;a(:)])~=0);
or
x = 999;
t = a ~= x;
out = a(t | [1,t(1:end-1)]);
0 件のコメント
Jan
2017 年 6 月 26 日
a = [1,2,999,999,3,45,5,999,999,999,999,6,5,8,999,5,67,8,999,7];
[B, N] = RunLength(a);
Result = max(N(B = 999));
Now the length of the longest sequence of 999s is replied.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!