2.3.1.2.1.5 Function Statements

There are two types of functions in Origin. One is the LabTalk Functions and the other is X-Functions.

LabTalk Functions

The syntax is functionname(arguement1, arguement2, ...)

Most LabTalk functions contains return type and can be used on the right hand side(RHS) of assignment statement or as argument of other command or functions.

Col(B)=sin(Col(A)); //call sine funciton
type $( total(Col(B)) ); //output total of column B


Some LabTalk functions automatically assigns values to built-in object or with no return type and can be called directly independently in a statement.

sum function will create a sum object with many basic stats result

sum(%C); //call function on selected dataset or active plot
sum.N=; //return total number of data
sum.total=; //return the total
sum.mean =; //return the mean
sum.= // check all properties of sum object

X-Functions

Though called function, it's called with similar syntax as commands, where square-brackets [ ] indicate optional:

xfname [-options] arg1:=value arg2:=value ... argN:=value;

The following script creates a new book, fill data and then do a linear fit, in which X-Functions newbook, fitlr are use together with LabTalk functions data(), uniform(), and sort().

newbook name:="Test"; //create a new book with name "Test"
col(A)=data(0.1, 10, .1); //fill column 0.1, 0.2, ... 10
col(B)=sort(uniform(100)); //fill column B with sorted uniformly distributed data from 0 to 1
fitlr iy:=(col(a), col(b)); //linear fit with tree object fitlr created. 
type "intercept is $(fitlr.a, .2)"; //output slope value with 2 decimal places
type "slope is $(fitlr.b, .2)"; //output slope value with 2 decimal places