if statement
7 views (last 30 days)
Show older comments
I am still getting used to the syntax of 'if' statements and would be much obliged on any suggestions on how to do the following: I need to create an if statement that would take stations files that are represented in a matrix for 3 separate bands of frequencies that meet a ratio cutoff of one for all 3 bands. I want to know which station files meet the criteria for all 3 of these bands and only use them for the further analysis that I need to do. I don't want to do this by hand (because I have some 260 events) and need some way of eliminating the stations for each event that don't meet that criteria. I want to do this either in the way of piping them into a new file or would appreciate advice on another way to do it as well. What I've done so far within my matrices is found for each of the three bands which stations don't meet this criteria by making them zero:
keep=sig2n510; indnot=find(sig2n510<1); keep(indnot)=0
I've done this for each of the three bands but would like to know if there's a better way and how to combine the results for the stations that meet it for all three bands. Thanks in advance!
Kayle
0 Comments
Answers (2)
Walter Roberson
on 12 Jul 2011
keep = (sig2n510<1) & (band2<Value2) & (band3<Value3);
keptband1 = sig2n510(keep);
keptband2 = band2(keep);
keptband3 = band3(keep);
Sean de Wolski
on 12 Jul 2011
It sounds like you may want to use cell arrays. Where each signal is a cell. The you do that operation to each cell with either cellfun or a for-loop.
doc cell
If you could provide a (small) set of sample data for maybe two signals, it would help us out more.
5 Comments
Sean de Wolski
on 12 Jul 2011
Okay, first read this:
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
It gives an overview of how to handle lots of files/variables.
What you want to do here is create one matrix:
sig = vertcat(sig2n510,sig2n1015,sig2n1520);
Now you can do the operation to each row of this matrix at a time
for example
sig(:,sig(1,:)<1)) = 0; %all columns that have the first row less than one are set to zero etc.
See Also
Categories
Find more on Excel Add-Ins 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!