3.10.3 Output to Results Log

Version Info

Minimum Origin Version Required: Origin 8 SR5


This example will use the curve_stats function to perform statistics, and then the results will be put to the Results Log.

Before running the Origin C code, please run the following LabTalk script first to generate the required data.

newbook;  // create a name workbook
fname$ = system.path.program$ + "Samples\Statistics\Descriptive Statistics on columns.txt";
impASC;  // import the file to the workbook
void output_results_log()
	Worksheet wks = Project.ActiveLayer();  // get the active worksheet
	DataRange dr;  // data range of column A and D
	dr.Add("X", wks, 0, 0, -1, 0);
	dr.Add("Y", wks, 0, 3, -1, 3);
	Tree trResult;
	if(!curve_stats(dr, trResult))  // perform statistics on column D, results to trResult
	Tree trRoot;  // root
	// create the tree node of the stats results
	TreeNode trStats = trRoot.AddNode("Results");  // the tree node of result
	TreeNode trN = trStats.AddNode("N");  // n total
	trN.dVal = trResult.N.dVal;
	TreeNode trSum = trStats.AddNode("Sum");  // sum
	trSum.dVal = trResult.sum.dVal;
	TreeNode trMin = trStats.AddNode("Minimum");  // min
	trMin.dVal = trResult.min.dVal;
	TreeNode trMax = trStats.AddNode("Maximum");  // max
	trMax.dVal = trResult.max.dVal;
	TreeNode trMean = trStats.AddNode("Mean");  // mean
	trMean.dVal = trResult.mean.dVal;
	TreeNode trMedian = trStats.AddNode("Median");  // median
	trMedian.dVal = trResult.median.dVal;
	TreeNode trSD = trStats.AddNode("SD");  // sd
	trSD.dVal = trResult.sd.dVal;
	string strResult;  // string of the tree node
	vector<int> vnTableDisplayFormat = {DISPLAY_CENTER, DISPLAY_RIGHT, DISPLAY_RIGHT};  // diaplay format
	if(0 < tree_to_str(trStats, strResult, vnTableDisplayFormat))  // convert tree node to string
		if(!Project.OutStringToResultsLog(strResult))  // output the string of the results to Results Log
			out_str("Failed to output the results to Results Log!\n");