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
 Forum for Origin C
 Substraction routine column row

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
Jengo Posted - 08/25/2010 : 11:30:01 AM
Origin Ver. and Service Release 8.1:
Operating System: Win XP

Hello,

Again I got a question because I am looking for a code that can help me with my routine:

sqrt( (x^n-x^n-1)²+(y^n-y^n-1)²/2)+x^n-1


I startet to find a code with 1-X-Column and 1-Y-Column

for one row No. 3 I have the following code:


a=(col(A)[3]-col(A)[2])^2;
b=(col(B)[3]-col(B)[2])^2;
col(C)[3]=(sqrt(a+b))/2+col(A)[2];


I tried to use this one
a=(col(A)[i]-col(A)[i-1])^2;
b=(col(B)[i]-col(B)[i-1])^2;
col(C)[i]=(sqrt(a+b))/2+col(A)[i-1];


an searched for some help in the files and online but did not find a solution, maybe it is too simple.....
the most important thing for me is to integrate the n and (n-1) but in which way????

I would be very glad for some help!

Greetings,
Jan
5   L A T E S T    R E P L I E S    (Newest First)
Penn Posted - 09/08/2010 : 10:02:50 PM
Hi Jan,

Please note that the script I provided was not the solution to your issue. It is just an example script to show you how to use the range variable to change the col(B) and col(New) that you had mentioned. I have made the script a little change, but not sure whether it is what you want.

for(jj=2; jj<=wks.ncols; jj++)
	for(ii=2; ii<=wks.maxrows; ii++)
	{
		range rd = [book2]sheet1!col($(jj-1));
		a=(col(A)[$(ii)]-col(A)[$(ii-1)]);
		b= (col($(jj))[$(ii)]-col($(jj))[$(ii-1)]);
		rd[$(ii)]=a+b;
	}

If it is not your requirement, you have to change the script according to your requirement, including how to calculate, how to arrange the results, etc.

Penn
Jengo Posted - 09/08/2010 : 09:54:57 AM
Hello,

still need help, so I post some pictures:

an example for my table (regular with a lot of more columns)



code only for col(B)
for(ii=2; ii<=wks.maxrows; ii++)
{
	range rd = [book2]sheet1!col(A)
	a=(col(A)[$(ii)]-col(A)[$(ii-1)]);
	b= (col(B)[$(ii)]-col(B)[$(ii)-1]);
	rd[$(ii)]=a+b;
}

code only for col(C)
{
	range rd = [book2]sheet1!col(B)
	a=(col(A)[$(ii)]-col(A)[$(ii-1)]);
	b= (col(C)[$(ii)]-col(C)[$(ii)-1]);
	rd[$(ii)]=a+b;
}


...

the result in book2:



because I need it for more columns I tried your one:

my simplified code in your style

for(ii=2; ii<=wks.maxrows; ii++)
{
range rd = [book2]sheet1!col($(ii-1))
a=(col(A)[$(ii)]-col(A)[$(ii-1)]);
b= (col($(ii))[$(ii)]-col($(ii))[$(ii)-1]);
rd[$(ii)]=a+b;
}

the result:


I dont want a diagonal :-/

I think the loop change the column after every calculation "a+b" but I need to change it only if one column is calculated.
And on the pages I could not find the right solution :-/
Penn Posted - 08/31/2010 : 10:02:11 PM
Hi Jan,

Though I am not sure how you want to change the col(B) and col(New), you can use the column index and range variable to change the column according to your requirement. You need to pay attention to the substitution notation. For example:

for(ii=2; ii<=wks.maxrows; ii++)
{
	range rNew = [book2]sheet1!col($(ii-1));  // use range
	a=(col(A)[$(ii)]-col(A)[$(ii-1)])^2;
	b=(col($(ii))[$(ii)]-col($(ii))[$(ii-1)])^2;  // use column index
	rNew[$(ii)]=(sqrt(a+b))/2+col(A)[$(ii-1)];
}


Penn
Jengo Posted - 08/31/2010 : 10:21:36 AM
Thanks! The code worked insofar as.

for(ii=2; ii<=wks.nrows; ii++)
{
	a=(col(A)[$(ii)]-col(A)[$(ii-1)])^2;
	b=(col(B)[$(ii)]-col(B)[$(ii-1)])^2;
	col(C)[$(ii)]=(sqrt(a+b))/2+col(A)[$(ii-1)];
}



I tried to adjust the code, but it didn't worked. :-/

col(B) in variable b needs to change after one column is calculated


and the results of one column should generate in a new column (same or another sheet/book)

for example:
1st:
{
a=(col(A)[$(ii)]-col(A)[$(ii-1)])^2;
b=(col(B)[$(ii)]-col(B)[$(ii-1)])^2;
col(new)[$(ii)]=(sqrt(a+b))/2+col(A)[$(ii-1)];
}
2nd
{
a=(col(A)[$(ii)]-col(A)[$(ii-1)])^2;
b=(col(C)[$(ii)]-col(C)[$(ii-1)])^2;
col(new)[$(ii)]=(sqrt(a+b))/2+col(A)[$(ii-1)];
}
3rd
and so on...

Sorry, that i could not find the right code by myself but I hope someone is able to help me.
Penn Posted - 08/25/2010 : 10:09:37 PM
Hi Jan,

I am not sure whether you just want to do some mathematical calculation by using the expressions you have provided. If so, you can use both LabTalk and Origin C to do that.

LabTalk script is:

for(ii=2; ii<=wks.nrows; ii++)
{
	a=(col(A)[$(ii)]-col(A)[$(ii-1)])^2;
	b=(col(B)[$(ii)]-col(B)[$(ii-1)])^2;
	col(C)[$(ii)]=(sqrt(a+b))/2+col(A)[$(ii-1)];
}


Origin C code is:

void doCal()
{
	Worksheet wks = Project.ActiveLayer();  // get the active worksheet
	if(!wks)
		return;
	
	Column colA = wks.Columns("A");  // get column A in worksheet
	Column colB = wks.Columns("B");  // get column B in worksheet
	Column colC = wks.Columns("C");  // get column C in worksheet
	
	if(!colA || !colB || !colC)
		return;
	
	vector& vA = colA.GetDataObject();  // get data of column A
	vector& vB = colB.GetDataObject();  // get data of column B
	vector& vC = colC.GetDataObject();
	
	for(int iRow=1; iRow<colA.GetNumRows(); iRow++)
	{
		double a = (vA[iRow]-vA[iRow-1])^2;
		double b = (vB[iRow]-vB[iRow-1])^2;
		vC[iRow] = (sqrt(a+b))/2+vA[iRow-1];
	}
}


The following pages may be useful for you to implement your routine.

About LabTalk: Loop Structures, Substitution Notation
About Origin C: Worksheet class, Column class

Penn

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