Combining matrices

3 views (last 30 days)
Paul
Paul on 9 Nov 2011
Edited: Paul on 2 Dec 2015
I'm trying to build a matrix with the number of occurences of a given condition from two matrices.
The objective is to now the number of points that correspond to a given statement and combining this into a m*n matrix to use on a plot
For example: how many waves have period<0.5 and height<1, how many waves have period<0.5 and 1<height<1.5. etc...
my class intervals are period=[0:1:17] and height=[0:0.5:10].
Is there a way to build a function that would in some way combine the two classes into a matrix that would help me build something like (I'm only interested in the numbers):
t=[period H] x=matrix size(t) %with the number of occurences of each class.
I tried using multiple for and if conditions and even simpler ways, but I'm feeling really lost.
Can someone help me?
thank you in advance
Paul

Accepted Answer

Paul
Paul on 9 Nov 2011
Basically, I want to do something like:
intervalHs=[0:0.5:10];
intervalTe=[0:1:20];
a=sum((Hs>0.5)&(Hs<1)&(Te<=1))
b=sum((Hs>2)&(Hs<=2.5)&(Te<=6)&(Te>5))
x=sum((Hs<=0.5)&(Te<=1))
y=sum((Hs<=0.5)&(Te>1)&(Te<=2))
z=sum((Hs<=0.5)&(Te>2)&(Te<=3))
and the construct a matrix (m*n) with the results

More Answers (2)

John Petersen
John Petersen on 9 Nov 2011
Paul, Try find() or a straight comparison (if you don't need to know the indices). For example,
function [num_periods, num_heights] = findnum(period,plowvalue,phighvalue,height,hlowvalue,hhighvalue)
num_periods = sum((period>plowvalue)&(period<phighvalue));
num_heights = sum((height>hlowvalue)&(height<hhighvalue));
  1 Comment
Paul
Paul on 9 Nov 2011
First, thanks for the answer.
I did tried to do something like that. Unfortunately that would mean I would have to insert all the possible combinations between the two classes one by one.
The idea is to count the number of waves that fall into both classes at once for each class interval (I'm finding some trouble in explaining).
For example: in the figure the value that corresponds to the number of waves that have a period between 5 and 6 s and a height between 1.5 and 2 is 584.
I know there must be a easy way of doing so, but I can't put my finger on it!

Sign in to comment.


Paul
Paul on 2 Dec 2015
Edited: Paul on 2 Dec 2015
THIS IS THE ACCEPTED ANSWER!!!!!!!!!!!!!!!!
I can't seem to undo my previou accepted answer....
y=0:1:20; %Te interval
x=0:0.5:10; %Hs interval
Hs=seccao1(:,2);
Tm=seccao1(:,3);
for n=1:20
Tm_id=Tm(Hs>x(n) & Hs<=x(n+1));
for k=1:20
s=sum(Tm_id>y(k) & Tm_id<=y(k+1));
M(n,k)=s; % M is a matrix with the number of occurences of each given interval (i.e: number of waves with %1<=Hs <1.5 and 5<=Te<6)
end
end

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!