if statement

7 views (last 30 days)
Katherine Anderson
Katherine Anderson on 12 Jul 2011
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

Answers (2)

Walter Roberson
Walter Roberson on 12 Jul 2011
keep = (sig2n510<1) & (band2<Value2) & (band3<Value3);
keptband1 = sig2n510(keep);
keptband2 = band2(keep);
keptband3 = band3(keep);
  1 Comment
Katherine Anderson
Katherine Anderson on 12 Jul 2011
Walter,
Thanks for the help, this allowed me to obtain which values corresponded to values less than 1. I changed it to obtain which cells corresponded to values greater than one because this is my interest. The problem is I need to be able to see which of the actual station files correspond to these cells and to save these stations only. Any suggestions?

Sign in to comment.


Sean de Wolski
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
Katherine Anderson
Katherine Anderson on 12 Jul 2011
I'm not sure cellfun is what I am looking for. What I'm trying to do is relate the particular cells that pass the ratio test for all 3 bands back to the files and somehow pass those corresponding files perhaps into a new .mat or .txt file with solely those station files in so I can know which ones to use for further analysis
Sean de Wolski
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.

Sign in to comment.

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!