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
 Plotting Fit data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Kaemme1909

8 Posts

Posted - 06/18/2013 :  05:40:37 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 9
Operating System: Win7

Hi together,

I like to plot my data from a fit to the plot from the original data. This is my code:
void PlotFitXY(int NUMB)
{
for(int i=1;i<=NUMB;i++)
{
WorksheetPage WSP= Project.WorksheetPages.Item(i);
Worksheet ws = WSP.Layers(0);
set_active_layer(ws);
LT_execute("plotxy iy:=(1,2) plot:=200");
bool bInit;
Operation& op = (Operation&)op_create("FitNL", bInit); // the operation name of NLFit is FitNL
if( !bInit )
{
out_str("Error in op create");
return;
}

Tree trOp;
op.GetTree(trOp);


if( !ws )
return;
DataRange dr;
dr.Add(ws, 0, "X");
dr.Add(ws, 1, "Y");

// init trOp.GUI.InputData treenodes from dr and do SetData, SetFunction actions
string strFunction = "ExpDec3";
string strCategory = "Exponential";
if (OP_NOERROR != op.OnInitDataFromOCLT(trOp, trOp.GUI.InputData, dr, strFunction, strCategory) )
{
out_str("Fail to init data from data range");
return;
}
op.SetTree(trOp);// set the changes of trOp back to op object

int nAutoUpdate = AU_AUTO;
op.OnNoEdit(0, nAutoUpdate);

op.Execute(); // do fit and genereate report
Worksheet wsp = WSP.Layers(2);
set_active_layer(wsp);
LT_execute("plotxy iy:=(1,2) plot:200");

}
}

The first plot and the fit is working, but I do not get the fit data plotted to the original graph.

Thanks for your help.

Penn

China
644 Posts

Posted - 06/18/2013 :  11:06:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Two issues:
1. The plotxy X-Function will create a new graph by default. If you want to get the fitted data plotted to the original graph, you have to specify the target graph to plot the fitted data.
2. There is a syntax mistake in this line, "=" is missing.

LT_execute("plotxy iy:=(1,2) plot:200");

I change your code like below, and it is able to plot the fitted data to the original graph.

void PlotFitXY(int NUMB)
{
	for(int i=1;i<=NUMB;i++)
	{
		WorksheetPage WSP= Project.WorksheetPages.Item(i);
		Worksheet ws = WSP.Layers(0);
		set_active_layer(ws);
		LT_execute("plotxy iy:=(1,2) plot:=200");
		
		// Get the graph
		GraphPage gp = Project.ActiveLayer().GetPage();
		if(!gp)
			return;
		
		bool bInit;
		Operation& op = (Operation&)op_create("FitNL", bInit); // the operation name of NLFit is FitNL
		if( !bInit )
		{
			out_str("Error in op create");
			return;
		}

		Tree trOp;
		op.GetTree(trOp); 


		if( !ws )
			return; 
		DataRange dr;
		dr.Add(ws, 0, "X");
		dr.Add(ws, 1, "Y");

		// init trOp.GUI.InputData treenodes from dr and do SetData, SetFunction actions
		string strFunction = "ExpDec3";
		string strCategory = "Exponential";
		if (OP_NOERROR != op.OnInitDataFromOCLT(trOp, trOp.GUI.InputData, dr, strFunction, strCategory) )
		{
			out_str("Fail to init data from data range");
			return;
		}
		op.SetTree(trOp);// set the changes of trOp back to op object

		int nAutoUpdate = AU_AUTO;
		op.OnNoEdit(0, nAutoUpdate);

		op.Execute(); // do fit and genereate report
		Worksheet wsp = WSP.Layers(2);
		set_active_layer(wsp);
		
		// Correct the syntax issue, and specify where to plot the fitted data
		LT_execute("plotxy iy:=(1,2) plot:=200 ogl:=[" + gp.GetName() + "]1!");

	}
}


Penn
Go to Top of Page

Kaemme1909

8 Posts

Posted - 06/21/2013 :  06:32:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for your help. Works fine.
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