# 3.5.8.22 WCol

The wcol(colNumExpression) function can be used either on the left side or on the right side of an assignment. The wcol function always expects an argument evaluating to a column number (1 .. N).

When wcol() is on the left side of the assignment, the right hand side should normally be a vector, not a scalar value. In the special case where a column has an assigned size you can assign a scalar value which gets replicated for the entire column:

wcol(1) = data(0,100,5; // Fills column one 0 to 100 in increments of 5
wcol(2) = 1; // Does nothing if column 2 is already empty
wcol(2) = wcol(int(pi)-2); // copies column 1 into 2
wcol(2) = 1; // Replaces all existing values in column 2 with "1"

Note: In the Wcol(colNumExpression) function , since the argument is always interpreted as an expression, you can use any expression which evaluates to a positive integer making it useful for looping over columns with a variable for example. This is different than the col(colNameOrNum) function where the argument must a column name or a literal number.

## Function Form:

 Wcol(colNumExpression)

## Examples

for (ii = 3; ii <= 10; ii += 1)
{
wcol(ii) = data(ii, ii+10);
};

In this case, if the worksheet contains only two columns, Origin creates new columns - the third to tenth column - as needed. Prior to Origin 8, this script would not create columns if they did not exist.

The following case shows how to set data, Long Name, Comments, and user parameters.

newbook;
wcol(1) = data(0, 6.3, 0.1);
wcol(2) = sin(wcol(1));
// Set Long Name
wcol(1)[L]$= X; wcol(2)[L]$ = Sine;
wcol(1)[C]$= "X Values"; wcol(2)[C]$ = "Sine Function";
wks.userParam1$= Purpose; // Set the first parameter wcol(2)[Purpose]$ = Graphing;