3.5.8.6 Col

Description

Col function refers to the dataset in a worksheet column. It can be on either the left hand side (LHS) or right hand side (RHS) of assignment statement.

Syntax

The parameter of col() function can either be String or number.

Syntax Description Example
Col(Name) Refer to column by specified name
Col(A) //col by short name first, then long name
Col("Amplitude") //column by long name
Col(Index) Refer to column by column index
Col(1) //1st column
Col(SName"LName") Refer to column with specified short name and long name
//useful if there are multiple columns with long name "Amplitude"
//Col("Amplitude") will refer to the leftmost column with such LName
 Col(D"Amplitude")

his case, if the Short Name is omitted, the left-most column with this Long Name will be referred to. |}

Note: Index is always interpreted as a value, which is different from Wcol(colNumExpression) function, where colNumExpression can be a numeric expression.

Entended Syntax

Add the following right after col() function to access to the corresponding row or column label row information of the specified column. It can be used on both LHS and RHS of Assignment.

  • [rowNum]
  • [rowNum]$
  • [LabelRowChar]
  • [LabelRowChar]$

where, LabelRowChar is one of the column label row characters or strings

Syntax Description Example
Col(NameorIndex)[rowNum] Value in the specified row of column
Col(A)[1] //1st row of column with short name A
Col(Time)[1] //1st row of column named Time (shortname first, then longname)
Col("Amplitude")[1] //1st row of column with long name Amplitude
Col(1)[1] //1st row in 1st column
Col(NameorIndex)[rowNum]$ Text in the specified row of column
Col(A)[1]$ //1st row of column with short name A
Col(Time)[1]$ //1st row of column named Time (shortname first, then longname)
Col("Amplitude")[1]$ //1st row of column with long name Amplitude
Col(1)[1]$ //1st row in 1st column
Col(NameorIndex)[LabelRowChar] Value in the specified column label row of column
Col(A)[D1] //1st user defined parameter of column A
Col(Time)[mean] //mean value row of column A
Col(NameorIndex)[LabelRowChar]$ Text in the specified column label row of column
Col(A)[L]$ //long name of column A
Col(Time)[U]$ //unit of column  named Time (shortname first, then longname)
Col(2)[C]$ //Comments of 2nd column

Examples

Example 1

newbook;
//assign dataset to column A
col(A)=data(0, 360, 30);
//For empty col, assign to scalar value does nothing
col(B)= 1; 
//calculate sine of col(A) and assign to col(B)
col(B)= sin(col(A));
//set col B's long name
col(B)[L]$="Sine"
//no column with long name "Cosine", so new column created with lname set
col("Cosine") = cos(Col(B)); 

//Add new col since Total not found, but column isn't renamed
Col(Total) = Col(B)+col(Cosine); //col(Cosine) search short name first and then long name

//Set the newly created column's long name to 'Sine+Cosine'
//Use substitution notation $(wks.ncols) to resolve the property to value first
Col($(wks.ncols))[L]$=Col(B)[L]$+"+" + Col("Cosine")[L]$; 

//If column isn't empty, can assign a scalar value to a column
col(A)= 0 ;

Example 2


Note: If the column has been set as categorical, Origin will return the category index of the cell specified by the given row and column numbers.

Col(colNameOrNum)[rowNum]$

The col(colNameOrNum)[rowNum]$ function can be used on either the left or right side of an assignment. When it is in the left side, it receives a string value to be assigned. When it is in the right side, it returns a string value of a single dataset element. Indicate the column name or column number in parentheses and the row number in brackets. The column name can be either the "short name" or the "long name". If the name is surrounded by double-quates("), it is regarded as a long name. When column name is NOT quoted, then the short name takes precedence. Origin returns the text of the cell specified by the given row and column numbers.

Function Form:

 Col(index)[rowNum]$, or Col(name)[rowNum]$

Col(colNameOrNum)[colHdrType]$

The col(colNameOrNum)[colHdrType]$ function accesses the column headers (e.g., Long Name, Units, Comment, Parameters, Sampling Interval and user-defined headers), and it has similar syntax to Col(colNameOrNum)[rowNum]$ .

Function Form:

 Col(index)[colHdrType]$, or Col(name)[colHdrType]$

Here, colHdrType is one of the column label row characters.

Example

Examples for Col(...)

  • Example 1
In the following example, if column C (specified at the left side of the assignment) does not exist, Origin creates a new column. (New! in Origin 8)
col(C) = (1+col(A)) / (1-col(B));

Examples for Col(...)[rowNum]

  • Example 1
In the following example, the variable myVar is assigned the value in the third row of column B.
myVar=col(B)[3];
  • Example 2
In the following example, the fourth cell of column B is assigned the value 9.
col(B)[4]=9;


Examples for Col(...)[rowNum]$

In the following example, the variable %W is assigned the text element in the third row of column A.
%W = col(A)[3]$;


Examples for Col(...)[colHdrType]$

  • Example 1
col(2)[L]$=my full name;  // set long name
%a=col(2)[U]$;  // get units
%a=col(2)[D2]$; // get the 2nd user defined header

See Also