Hello,
I have a little problem, I do not know how to calculate a occurence of couple of value.
I explain,
I have some waves datas (3600) with height and direction.
HsW=[2 5 1 3]; %height
DirW=[42 24 35 45];% direction
for exemple : I want to calculate the occurence of the couple 2 42 ,5 24 in my datas.
I have seen some matlab function like tabulate but it's always for vector, not for array.
Is there some functions or code that's can do that.
Hoping that you can help me,

 採用された回答

dpb
dpb 2019 年 7 月 13 日

1 投票

HD=[HsW;DirW].'; % combine data for convenience
Pattern=[HD(1:2,:)]; % the looked for pattern
[~,l2]=ismember(HD,Pattern,'rows'); % locations where pattern was found
N=sum(l2((l2==1)+1)==2); % count locations of L1 followed by L2
Above doesn't account for (assumed rare) possibility that the pattern line 1 may be the last element in the array. If that case were to occur, augment the l2 vector with a NaN or any nonmatching value to avoid the bounds error from the +1 address expression.
The locations of the match are simply
find(l2((l2==1)+1)==2)
It's often simpler to turn into strings for pattern matching as then one can make simply a byte comparison of vector or array of characters

1 件のコメント

Bossennec Guillaume
Bossennec Guillaume 2019 年 7 月 15 日
Ok thanks for your answer,
that's help me,
I will try with string to improve my skills,

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by