From: Andrew Liu on 7 Jul 2010 17:55 Hello, I'm trying to output data from for loops and from if statements. right now my code is this: for i=1:length(time) for ii = 1 if time(i,1) > 0 & time(i,1) <= (60*15); value = sum(ppt_data(1:ii)); break elseif time(i,1) > (60*15) & time(i,1) < (60*30) value = sum(ppt_data(1:ii)); end end end I'm not even sure if I'm doing it right. Anyways, I would like to output data in 1 file one at a time if it satisfies the condition (if it is true, output data. Then if it goes to the elseif statement and if that is true, output the data right after the previous statement). So far, its just outputting everything.
From: dpb on 7 Jul 2010 20:03 Andrew Liu wrote: > Hello, > > I'm trying to output data from for loops and from if statements. > > right now my code is this: > > for i=1:length(time) > for ii = 1 % This is a do-nothing??? > if time(i,1) > 0 & time(i,1) <= (60*15); > value = sum(ppt_data(1:ii)); > break > elseif time(i,1) > (60*15) & time(i,1) < (60*30) > value = sum(ppt_data(1:ii)); > end > > end > > end > > I'm not even sure if I'm doing it right. > > Anyways, I would like to output data in 1 file one at a time if it > satisfies the condition (if it is true, output data. Then if it goes to > the elseif statement and if that is true, output the data right after > the previous statement). So far, its just outputting everything. I'm having a hard time parsing the request combined w/ the code... For one thing, the loop on ii does nothing other than the break will not leave the outer loop. Is that the purpose for having it? Even if so, what's the purpose of the break statement, anyway? And, I don't see any output so not sure what the desired output would be. I'd probably start by trashing the loop(s) anyway and use a couple of logical tests on the time() array to return the indices in the desired time frame and operate on the data array via that logical index array, then output whatever was wanted in the end. But, not having a detailed idea of what _is_ wanted, that's conjecture...won't go so far as to send the crystal ball to the shop just yet; it's just murky. --
From: Andrew Liu on 7 Jul 2010 20:43 Thanks for your response. Is there a way I can contact you privately? Thanks
From: someone on 7 Jul 2010 20:49 "Andrew Liu" <nospam(a)gmail.com> wrote in message <i12t48$6t4$1(a)fred.mathworks.com>... > Hello, > > I'm trying to output data from for loops and from if statements. > > right now my code is this: > > for i=1:length(time) > for ii = 1 > if time(i,1) > 0 & time(i,1) <= (60*15); > value = sum(ppt_data(1:ii)); > break > elseif time(i,1) > (60*15) & time(i,1) < (60*30) > value = sum(ppt_data(1:ii)); > end > > > end > > end > > I'm not even sure if I'm doing it right. > > Anyways, I would like to output data in 1 file one at a time if it satisfies the condition (if it is true, output data. Then if it goes to the elseif statement and if that is true, output the data right after the previous statement). So far, its just outputting everything. Like dpb, I am having a hard figuring out what you are trying to do. But one thing you should be aware of: the if - elseif - end condition is an either - or ( or neither) condition. If the first condition is true, the rest of the elseif condition is skipped (it doesn't THEN test the elseif condition). If the first condition is false, THEN the next elseif condition is tested (and so on). To do what you described, you need two if statements, something like: if time(i,1) > 0 & time(i,1) <= (60*15); value = sum(ppt_data(1:ii)); end if time(i,1) > (60*15) & time(i,1) < (60*30) value = sum(ppt_data(1:ii)); end
From: Andrew Liu on 7 Jul 2010 21:34
ooooooo thank you. i see, i will try it out. Do u mind if I contact you too? |