Occurence with 2 variables
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Bossennec Guillaume
am 12 Jul. 2019
Kommentiert: Bossennec Guillaume
am 15 Jul. 2019
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,
0 Kommentare
Akzeptierte Antwort
dpb
am 13 Jul. 2019
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!