<?xml version="1.0"?>
<OriginStorage FileName="D:\OriginPro80\Samples\Programming Guide\X-Functions\vector_stats_ex.OXF" Display="652" Label="System: vector_stats_ex"><XFname NodeID="11" Label="Name" DataID="300">vector_stats_ex</XFname><xFdescription NodeID="11" Label="Description" DataID="310"></xFdescription><attachTo NodeID="13" Label="Attach to Origin Object" Combo="None|Auto|Column|Sheet/Layer|Book/Graph" DataID="320">1</attachTo><UsageCtxt NodeID="268435456" Label="Usage Context" DataID="329" Use="1"><LabTalk NodeID="10" Label="Labtalk" DataID="357">1</LabTalk><WksSel NodeID="10" Label="Worksheet Selection" DataID="350">1</WksSel><WksSel NodeID="10" Label="Worksheet Selection Change" DataID="355">0</WksSel><WksSel NodeID="10" Label="Worksheet Selection Tracking" DataID="356">0</WksSel><GrObj NodeID="268435456" Label="Graphic Object Events" DataID="330" Use="0"><InitAnchors NodeID="10" Label="Initialization" DataID="339">1</InitAnchors><Move NodeID="10" Label="Move" DataID="331">1</Move><Moving NodeID="10" Label="Moving" DataID="332">0</Moving><Resize NodeID="10" Label="Resize" DataID="333">0</Resize><Resizing NodeID="10" Label="Resizing" DataID="334">0</Resizing><Delete NodeID="10" Label="Delete" DataID="335">0</Delete><Select NodeID="10" Label="Select" DataID="336">0</Select><Unselect NodeID="10" Label="Unselect" DataID="337">0</Unselect><BtnClick NodeID="10" Label="Button Click" DataID="338">0</BtnClick><Rotate NodeID="10" Label="Rotate" DataID="340">0.</Rotate><Rotating NodeID="10" Label="Rotating" DataID="341">0.</Rotating><Skew NodeID="10" Label="Skew" DataID="342">0.</Skew><Skewing NodeID="10" Label="Skewing" DataID="343">0.</Skewing><EditEv NodeID="10" Label="Edit" DataID="344">0.</EditEv><Editing NodeID="10" Label="Editing" DataID="345">0.</Editing></GrObj><ToXFHeader NodeID="10" Label="Declare in xf.h" DataID="358">0</ToXFHeader></UsageCtxt><vars NodeID="268435456" Label="Variables" Branch="1" MoveRows="" EditCol="1|1|1"><v1 NodeID="268435456" _XFUNCTION_VAR="1" RepeatID="1" Branch="1"><name NodeID="11" Label="Name" DataID="10">x</name><description NodeID="11" Label="Description" DataID="20">selected data combined into a single vector</description><io NodeID="13" Label="Input/Output" Combo="Input|Output|Input/Output" DataID="30" Handler="117856680">0</io><type NodeID="11" Label="Data Type" Combo="double|string|int|vector|Range|XYRange|XYZRange|matrix|MatrixObject|ButtonInfo|LineInfo|TextInfo|EventInfo|MarkerInfo" DataID="40" Handler="117856680">vector</type><valdata NodeID="35" Label="Data" DataID="50">col(1)</valdata><Context NodeID="268435456" Label="Context"/><Data NodeID="268435456" Label="New Output Data" DataID="911" Branch="2048" Use="0" Show="0"><Book NodeID="11" Label="Book" Combo="&lt;active&gt;|&lt;new&gt;|&lt;source&gt;|&lt;existing&gt;..." DataID="903" Handler="115826032">&lt;active&gt;</Book><Sheet NodeID="11" Label="Sheet" Combo="&lt;active&gt;|&lt;new&gt;|&lt;existing&gt;..." DataID="904" Handler="113465440" Enable="1">&lt;active&gt;</Sheet><ColumnName NodeID="11" Label="Column" DataID="912">Default</ColumnName><XColumnName NodeID="11" Label="XColumn" DataID="913">X</XColumnName><YColumnName NodeID="11" Label="YColumn" DataID="914">Y</YColumnName><ZColumnName NodeID="11" Label="ZColumn" DataID="915">Z</ZColumnName></Data></v1></vars><header NodeID="45" Label="Header" DataID="323" RowHeightRange="3-15"><![CDATA[#include <origin.h>

typedef struct tagVStat
{
	double dMin;     // Minimum Value
	double dMax;     // Maximum Value
	uint nMin;       // Index of Minimum Value
	uint nMax;       // Index of Maximum Value
	uint nPts;       // Number of Data Points
	uint nMissing;   // Number of Missing Values
	double dSum;     // Sum of Values
	double dMean;    // Mean of Values
} VStat;

static void _compute_vector_stats(const vector& x, VStat& MyVStat)
{
	int nn = x.GetSize();
	MyVStat.dSum = ocmath_d_sum(x, nn, &MyVStat.dMin, &MyVStat.dMax, &MyVStat.nMin, &MyVStat.nMax, &MyVStat.nPts);
	MyVStat.nMin++;
	MyVStat.nMax++;
	MyVStat.nMissing = nn - MyVStat.nPts;
	if( MyVStat.nPts > 0 )
		MyVStat.dMean = MyVStat.dSum/MyVStat.nPts;
	else
		MyVStat.dMean = NANUM;
}

static void _print_vector_stats(VStat& MyVStat)
{
	LT_execute("type -a"); // Make sure script window is open
	printf("Minimum Value = %g\n", MyVStat.dMin);
	printf("Maximum Value = %g\n", MyVStat.dMax);
	printf("Index of Minimum Value = %d\n", MyVStat.nMin);
	printf("Index of Maximum Value = %d\n", MyVStat.nMax);
	printf("Number of Data Points = %d\n", MyVStat.nPts);
	printf("Number of Missing Values = %d\n", MyVStat.nMissing);
	if( MyVStat.nPts > 0 )
	{
		printf("Sum of Values  = %g\n", MyVStat.dSum);
		printf("Mean of Values = %g\n", MyVStat.dMean);
	}
}]]></header><code NodeID="45" Label="Expression" DataID="325" RowHeightRange="5-20"><![CDATA[VStat theVStat;
_compute_vector_stats(x, theVStat);
_print_vector_stats(theVStat);]]></code></OriginStorage>
