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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 nested loops in labtalk
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

bo257

USA
13 Posts

Posted - 04/22/2004 :  4:58:59 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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;}

Mike Buess

USA
3037 Posts

Posted - 04/22/2004 :  5:21:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000