Output to Script Window
Version Info
Minimum Origin Version Required: Origin 8 SR5
Example
This example will use the curve_stats function to perform statistics, and then the results will be put to the Script Window.
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_script_window()
{
Worksheet wks = Project.ActiveLayer(); // get the active worksheet
if(!wks)
return;
DataRange dr;
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
return;
Tree trRoot; // root
// create the tree node of the stats results
TreeNode trStats = trRoot.AddNode("DescriptiveStatsReport"); // 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
{
LT_execute("type -a");
out_str(strResult); // output the string of the results
}
}
|