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
 Forum for Origin C
 Save data to a column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kineticesp

Colombia
12 Posts

Posted - 07/29/2008 :  7:01:20 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Im trying to operate a column with a number and save the result in a column, in origin is pretty simple but in OriginC i cant seem to do it.

I did this:


vector data;
data=wks.Columns(ii).GetInternalData();
data=data*5000/4096;
wks.Columns(ii).SetInternalData(data);

And it doesnt work.


Someone please help me..

Thanks

Sophy

China
Posts

Posted - 07/30/2008 :  05:04:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, I think SetInternalData is a method to specify the format of a column. To set the value of a specified column , we can use Dataset and attach it to the column. Operation on Dataset will take effect instantly on corresponding column.
See:

void test_set_value()
{
	//Get the first workbook's first worksheet layer
	Worksheet wks = Project.WorksheetPages(0).Layers();
	if( !wks )//validate it
		return;

	Dataset ds; //derived from vector
	ds.Attach( wks, 0 ); //operation on ds will take effect instantly on corresponding column, here it's the first column
	if( ds.IsValid() )
		ds = ds * 5000 / 4096;
	return;
}
Go to Top of Page

kineticesp

Colombia
12 Posts

Posted - 07/30/2008 :  10:05:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you so much!!

Go to Top of Page

kineticesp

Colombia
12 Posts

Posted - 07/30/2008 :  1:25:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ok so it worked, I now understand the Dataset behaviour (adding datasets to columns etc), but there are other types of data Im working with that I dont fully understand.

For example Im trying to save data from a vector to a Column or viceversa, and I really dont understand how.

Im stucked.
help!
Go to Top of Page

Sophy

China
Posts

Posted - 07/30/2008 :  10:50:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, in this case , I think GetDataObject() is a better way to solve your problem.The function return a reference of a column as a vectorbase, then you can set value on it.
Example:

void test_operation_on_column()
{
	//Get the first workbook's first worksheet's active layer
	Worksheet wks = Project.WorksheetPages(0).Layers();
	if( !wks )
		return;
	
	Column col = wks.Columns(0);			//get the first column of the worksheet
	if( !col )
		return;
	
	vectorbase&	vb = col.GetDataObject();	//get the reference of a column
	vector		vecMy;						// customer data
	vecMy.Data( 0, 20, 2 ); 
	vb = vecMy;								//set customer data,operation on vb will take effect instantly on column, or you can change elements of vb directly
	return;
}

To set value on columns with special type, say Time, Text other than Numeric, you may need to call Column::SetFormat( int format ) first.
The column format,enum { OKCOLTYPE_NUMERIC, OKCOLTYPE_TEXT, OKCOLTYPE_TIME, OKCOLTYPE_DATE, OKCOLTYPE_MONTH, OKCOLTYPE_WEEKDAY, OKCOLTYPE_TEXT_NUMERIC}.
For other problems, please feel free to post them. Thanks
Go to Top of Page

kineticesp

Colombia
12 Posts

Posted - 07/31/2008 :  09:44:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks again!, Im sorry I have to post so much but I didn't find a complete reference guide for OriginC and this is all new to me.

All these questions relate to a basic function Im trying to implement.

I want to do a "Adjacent Averaging Smooth" in OriginC. Lets narrow the problem so that you can understand me better.

I have a worksheet with 3 columns, col(0) is the X and is time format, col(1) is the Y values of the signal and col(2) will hold the result of the smooth operation;so far, here is what i've done using the information of the above posts.

Column smi, smo;  //Declare variables 
	vector vy, vSmooth;

        smi= wks.Columns(1);
	if(!smi)
		return;
	smo= wks.Columns(2);
	if(!smo)
		return;
	
	vectorbase& vsmo=smo.GetDataObject();
	vectorbase& vsmi=smi.GetDataObject();
	
	vSmooth=vsmo;
	vy= vsmi;
	
	ocmath_adjave_smooth(vy, vSmooth, vy.GetSize(), 5);

	vsmo=vSmooth;


Doing this I get the error "External call execution error".

Regarding to the code, I used vectors because the example uses vectors as parameters of the ocmath_adjave_smooth although I dont see where is the information of the X (time).
The example in the Origin C tutorial uses Datarange but I dont understand that type of Object.


I need some help again :)

Edited by - kineticesp on 07/31/2008 09:53:26 AM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 08/01/2008 :  9:16:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I think the problem is that your output column started out empty and the copy you made in the code is thus empty so there is no actual memory space to pass into ocmath_adjave_smooth.

Using a vector copy instead of directl using vectorbase from Column is because by default a column's data is not numeric double, but Text & Numeric which is not contiguous memory array.

here is the modified code

	Worksheet wks = Project.ActiveLayer();
	Column smi, smo;  //Declare variables 
	vector vy, vSmooth;

	smi= wks.Columns(1);
	if(!smi)
		return;
	smo= wks.Columns(2);
	if(!smo)
		return;
	
	vectorbase& vsmo=smo.GetDataObject();
	vectorbase& vsmi=smi.GetDataObject();
	
	vSmooth=vsmo;
	vy= vsmi;
	
	vSmooth.SetSize(vy.GetSize()); // must prepare vector with enough size first.
	
	ocmath_adjave_smooth(vy, vSmooth, vy.GetSize(), 5);

	vsmo=vSmooth;

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