Combining matrices

조회 수: 5 (최근 30일)
Paul
Paul 2011년 11월 9일
편집: Paul 2015년 12월 2일
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

채택된 답변

Paul
Paul 2011년 11월 9일
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

추가 답변 (2개)

John Petersen
John Petersen 2011년 11월 9일
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
Paul
Paul 2011년 11월 9일
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!

댓글을 달려면 로그인하십시오.


Paul
Paul 2015년 12월 2일
편집: Paul 2015년 12월 2일
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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by