The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 nested loops in labtalk

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

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++}

stat.data$ = Data1_B$(ii);
stat.pr.order = 4;
stat.pr();

for (jj = 1; jj <= $(numberOfRows); jj++) {
%A = $(Data1_B$(ii)[$(jj)]) - $(stat.pr.a);
%B = %A - $(Data1_B1[$(jj)])*$(stat.pr.b1);
%A = %B - $(Data1_B1[$(jj)])^2*$(stat.pr.b2);
%B = %A - $(Data1_B1[$(jj)])^3*$(stat.pr.b3);
%A = %B - $(Data1_B1[$(jj)])^4*$(stat.pr.b4);
Data1pr_B$(ii)[$(jj)] = %A;}
1   L A T E S T    R E P L I E S    (Newest First)
Mike Buess 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.

loop (ii,1,wks.ncols) {
- do something etc. -
};

Mike Buess
Origin WebRing Member

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000