Combining matrices
Show older comments
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
More Answers (2)
John Petersen
on 9 Nov 2011
0 votes
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));
Categories
Find more on Annotations 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!