You are on page 1of 4

[Column Subrange ([i-3:i+4]), Moving SD]

stddev(col(A)[i-3:i+4]);
#// Calculate standard deviations of moving ranges [i-3, i+4] in column A

[Power Operator (^)]


col(A)^3;
#//Calculate the cube of column A

[Conditional Operator (?:)]


col(A)==1/0 ? mean(col(A)) : col(A);
#//Replace missing values in column A with the column's mean

[String Concatenation (+)]


col(A)$+col(B)$;
#//Concatenate the text in column A and column B

[String Expression Substitution (%)]


%(col(A)[C]$)*cos(col(A)/180*pi);
#//Suppose theta in column A and r value in its Comments label
//Calculate x from column A

[OriginSeparator1]

[Using Function: Convert a Fraction to a Decimal]


frac2decimal(col(A));
#//declare a function to convert from a fraction into a decimal
function double frac2decimal(string str)
{ double aa = %(str$); return aa; }

[String Function: Convert to Standardized City Names]


stdnames(col(A))$;
#//Convert strings in col(A) to standardized city names
Function string stdnames(string str)
{
if(search(str$, "ny")>0)
return "New York";
if(search(str$, "LA")>0)
return "Los Angeles";

return str$;
}

[Function with Two Datasets as Inputs: Convolution]


convfunc( col(A), col(B) );
#//Calculate circular convolution of column A and column B
Function dataset convfunc( dataset ds1, dataset ds2 )
{
Dataset ds3, ds4;
conv ix:= ds1 response:=ds2 circular:=1 oy:=(ds3,ds4);

return ds4;
}

[OriginSeparator2]

[Column Range: Adding 1st Two Columns]


a+b;
#// declare range for col(1) and col(2)
range a =1, b=2;
[Calculation between Columns in Another Sheet]
a*b;
#//New a workbook within one sheet
%a=%h;
newbook name:=SampleData sheet:=1 option:=1;
//Declare range for columns in the 1st sheet of another book
range a=[SampleData]1!1, b=[SampleData]1!2;
a={1:10};
b={0.1:0.1:1};
win -a %a;

[Relative Column and Row Index]


;// Nothing to do here
#// Copy two columns inverted and shifted down
newbook;
end = 10; // 10 rows
col(1) = data(1,end);
col(2) = uniform(end);
wks.ncols = 4;
// Illustrate relative addressing in column and rows
loop(jj,3,4)
{
for( ii = end ; ii > 0 ; ii-- )
{
wcol(jj)[end - ii + 7] = wcol(jj-2)[ii];
}
}

[Relative Column Index]


(a+b)/2;
#//you can update values on the next column as well
const nn=_ThisColNum;
range a=wcol(nn-2),b=wcol(nn-1);
range next=wcol(nn+1);
next=(a-b)/2;

[Sample Using Ranges]


a*exp(-rr/w);
#// This sample expects data in columns 1 and 2
// Whatever column this is run in will be replaced
// with result
// declare range for col(1) and col(2)
range x=1,y=2;

// temp dataset as intermediate variable


dataset rr;
rr = x^2+y^2;

// also declare some local constants


const a=12.3, w = 2*pi;

// show these values whenever col is updated


ty -a;list a;

[OriginSeparator3]

[Loop Columns: Fill Multiple Columns of Data]


;
#// simply fill 100 columns of data
//columns will be automatically added by the wcol function
loop (i,1,100) {
wcol(i)={0:0.01:i+2};
}

[Column Index j: Statistics on Multiple Columns]


;
#//Statistics on first five columns in the worksheet.
wcol(j)[1] = mean(wcol(j-5));
wcol(j)[2] = stddev(wcol(j-5));

[Subtract Baseline for Multiple Curves]


j==1?r2x : r2-r1;
#//Baseline in the first worksheet
range r1=[Book1]Sheet1!col(2);
//Curves XYY in the second worksheet
range r2x=[Book2]Sheet1!col(1);
range r2=[Book2]Sheet1!wcol(j);

[OriginSeparator4]

[Moving Median Using Subrange]


median(col(A)[i-5:i+5],3);
#// Calculate medians of moving ranges [i-5, i+5] in column A

[Normalize Column to (0,1)]


;
#// Get index of current column
const nn = _ThisColNum;
// Get min and max using stats XF
stats wcol(nn);
// Subtract min and scale by (max-min)
wcol(nn) -= stats.min;
wcol(nn) /= (stats.max - stats.min);

[Compute Cumulative Sum]


;
#// Get index of current column
const nColIn = _ThisColNum;
// Add a new column for sum output
wks.addcol();
const nColOut = wks.ncols;
// Compute sum and set long name of output col
wcol(nColOut) = sum(wcol(nColIn));
wcol(nColOut)[L]$ = "Sum of " + wks.col$(nColIn).name$;

[Difference between Rows]


diff(col(A));
#// Calculates row by row difference

[Using X-Function: Statistics on Rows]


;
#//row stats on all columns to the left
//we will do all the scripting here, column formula can be empty
const nn=_ThisColNum;
range mean=wcol(nn), sd=wcol(nn+1), npts=wcol(nn+2);
rowstats 1:wcol(nn-1) mean:=mean sd:=sd n:=npts;

sd.type = 3;//YErr
mean.type = 1;//Y
npts.type = 2;//disregard, not to plot

ss$=mean.Label$; if(ss.IsEmpty()) mean.Label$="Mean";


ss$=sd.Label$; if(ss.IsEmpty()) sd.Label$="StDev";
ss$=npts.Label$; if(ss.IsEmpty()) npts.Label$="N Size";

You might also like