Note: You must be registered in order to post a reply. To register, click here. Registration is FREE!
T O P I C R E V I E W
bo257
Posted - 04/22/2004 : 4:58:59 PM Hi; Starting from a wks which contains 1 x column and 300 y columns I would like to do the following:
1) plot one column at a time. 2) do a polynomial fit of order 4 for each plot 3) substract original plot from the polynomial fit 4) write this difference for each plot into a column of a new worksheet 5) Repeat step 1) to 4) for all 300 column by using a for loop.
The steps 1) to 4) seems to work, but if I try do this with a for loop for all 300 columns I have a problem. Is it possible to have nested loops in labtalk?
I have included the code below and marked the point where I would have a second for loop with xxx.
Thanks for any comments:
numberOfColumns = 300; numberOfRows = 300;
// change name of columns; first run only for (ii = 1; ii <= $(numberOfColumns); ii++) { work -n $(ii) DATA$(ii);}; for (ii = 1; ii <= $(numberOfColumns); ii++) { work -n $(ii) B$(ii);}; // finish change name of columns
win -a Data1; work -d Data1pr; // first run only ClearWorksheet Data1pr; // first run only
win -a Data1; //xxx here I would like to put a second for loops which loop //through the 300 columns "for (ii = 1; ii //= "$(numberOfColumns);ii++}
Posted - 04/22/2004 : 5:21:19 PM Nested loops work fine in LabTalk. (Just make sure they don't loop over the same variables.) You could write the second loop like this...
for(ii=i; ii<=wks.ncols; ii++) { - do something to each column in the active worksheet - };
Note: 'loop' loops are better than 'for' loops for simple iterations like this because they are more efficient. With 300 columns the following might be noticeably faster than the 'for' loop above.