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,

 Respuesta aceptada

dpb
dpb el 13 de Jul. de 2019

1 voto

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 comentario

Bossennec Guillaume
Bossennec Guillaume el 15 de Jul. de 2019
Ok thanks for your answer,
that's help me,
I will try with string to improve my skills,

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 12 de Jul. de 2019

Comentada:

el 15 de Jul. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by