if statement

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

Antworten (2)

Walter Roberson
Walter Roberson am 12 Jul. 2011

0 Stimmen

keep = (sig2n510<1) & (band2<Value2) & (band3<Value3);
keptband1 = sig2n510(keep);
keptband2 = band2(keep);
keptband3 = band3(keep);

1 Kommentar

Katherine Anderson
Katherine Anderson am 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?

Melden Sie sich an, um zu kommentieren.

Sean de Wolski
Sean de Wolski am 12 Jul. 2011

0 Stimmen

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 Kommentare

Katherine Anderson
Katherine Anderson am 12 Jul. 2011
Sean de,
I am going to look into cellfun. I'm already using for loops to loop through each individual file corresponding to the stations. What I have is a 1x20 matrix which corresponds in rows to the SNR ratio and each column is a station. I need to somehow figure out how to obtain the cells(i.e. stations) that correspond to meeting the criteria for each of the 3 bands (ratio>1) and keep those stations, but I want to relate it back to the actual station files and because of my inexperience in Matlab am trying to find an intelligible way to do so. Since I'm new to this forum, if you'd be obliged to tell me how I could share some of the matrices with you I would gladly do so.
Sean de Wolski
Sean de Wolski am 12 Jul. 2011
Either through a free file hosting website or (if they're small enough) just by editing your question to include them.
Welcome to MATLAB Answers!
Katherine Anderson
Katherine Anderson am 12 Jul. 2011
Thanks for the warm welcome: Here's the matrices I'm trying to deal with, again I have a 1x20 matrix for each of the 3 bands, the rows correspond to snr and the columns to stations:
sig2n510=[1.4531 1.7170 0.9060 3.1719 0.4768 0.3054 0.6034 0.3414 2.6788 0.8688 0.3272 1.5170 3.1623 3.6298 1.8635 0.4895 1.9247 2.0948 0.7010 0.7809]
sig2n1015=[5.4986 1.0464 0.1845 6.6086 0.4474 0.4596 0.5764 1.0696 0.5088 0.7671 0.5074 1.7563 1.1067 9.9847 2.3045 0.7637 10.2725 3.5242 2.0309 0.4713]
sig2n1520=[2.1400 1.9445 0.5847 1.3805 1.9824 1.3288 1.7031 6.5701 1.5658 1.1464 0.4964 2.1567 0.6758 1.0343 1.0366 2.6039 3.5115 1.2723 1.5931 35.1411]
Katherine Anderson
Katherine Anderson am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 12 Jul. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by