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
 problem with sum in for loop

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
G.Bartsch Posted - 09/13/2005 : 06:31:34 AM
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.
3   L A T E S T    R E P L I E S    (Newest First)
G.Bartsch Posted - 09/13/2005 : 12:36:26 PM
thank you very much. now it finally works.
Mike Buess Posted - 09/13/2005 : 12:19:56 PM
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
G.Bartsch Posted - 09/13/2005 : 12:05:05 PM
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]));
};

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