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
 problem with sum in for loop
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

G.Bartsch

Germany
Posts

Posted - 09/13/2005 :  06:31:34 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I just want to have a script that sums each column and writes these sums into another worksheet. Principally the following script works well, but for the columns 14 and 15 it writes no values. I tested the critical for loop even with no dependencies to the index of summation - nevertheless no values at 14 and 15. The error shouldnt be so difficult to find but as a poor programmer I really don't see the problem.
This is the complete script, just for the sake of completeness. Critical part at the very end of it.

%W=%H;
o=2;

//delete cols

cols=%W!wks.ncols;
step=1;
i=3;
repeat ((cols-i)/(step+1)){
delete col($(i));
i+=step;
};

//rename cols

cols=%W!wks.ncols;
for(i=1; i<=cols;i+=1)
{
%W!wks.col$(i).name$=$(i-1)
};

//create new worksheet;


if (integrals_B==--)
{
cols=%W!wks.ncols;
create.wksName$ = "Integrals";
create.npts = (cols-1);
create.numtypes = 2;
create.type1 = 4;
create.type2 = 1;
create.wks(B);

Integrals!wks.addcol(Int);

//write Bfield

cols=%W!wks.ncols;
for (ii = 2; ii <= cols; ii += 1)
{
Integrals!cell($(ii-1),1) = %W!cell(1,$(ii));
};

mark -d %W_1 -b 0 -e 1;

//absolute

cols=%W!wks.ncols;
for(i=1; i<=cols;i+=1)
{
%W_$(i)=abs(%W_$(i));
};
};
else
{
Integrals!wks.addcol(Int);
o=o+1;
};


//integration

maxrows=%W!wks.nrows;
rows=%W!wks.maxrows;

getnumber (left border) lb (right border) rb (given in pixels);

for(i=1; i<=(cols-1);i+=1)
{
Integrals!cell($(i),$(o))=($(sum(%W_$(i))[rb])-$(sum(%W_$(i))[lb]));
};



thank you for your time.

G.Bartsch

Germany
Posts

Posted - 09/13/2005 :  12:05:05 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
well, did i mension that this is quite urgent? no? ok - its urgent ;).

to make the problem more obvious: please explain, why this for loop doesnt produce values for i=14 and i=15. %W could be any worksheet with some values in the first column.

for(i=1; i<=20;i+=1)
{
type $($(sum(%W_$(1))[2])-$(sum(%W_$(1))[1]));
};
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/13/2005 :  12:19:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Don't know why those values of i don't work but you can fix it with this slightly more efficient script. (More efficient because it only sums once per iteration)

for(i=1;i<=20;i+=1)
{
tmp=sum(%W_$(i));
type $(tmp[2]-tmp[1]);
del tmp;
};

...In general, you are using the $() notation too much. It's generally needed only to convert a numeric value to string. For example, this version of the final routine in your original text should work fine if all columns in Integral wks are text+numeric...

for(i=1; i<=(cols-1); i+=1)
{
tmp=sum(%W_$(i));
Integrals!cell(i,o)=tmp[rb]-tmp[lb];
del tmp;
};

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/13/2005 12:28:51 PM

Edited by - Mike Buess on 09/13/2005 12:41:50 PM
Go to Top of Page

G.Bartsch

Germany
Posts

Posted - 09/13/2005 :  12:36:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thank you very much. now it finally works.
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