Occurence with 2 variables

1 次查看(过去 30 天)
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
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
Ok thanks for your answer,
that's help me,
I will try with string to improve my skills,

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by