Show Column’s Mean and Size in Column Label Rows

In Origin 2018 and 2018b, we support cell formula in User-Defined Parameter rows and Data area of worksheet. You can easily type =Mean(C) to calculate mean of column C or =Mean(This) to calculate mean of current Column.

 

In Versions before Origin 2018, you can calculate each column’s mean and size in worksheet and put them in column label rows by a few lines of LabTalk Script.

wks.userparam1$ = Mean; //define a user-defined parameter row
wks.userparam1 = 1; //show this row named "Mean"
wks.userparam2$ = Size;//do the same for a "Size" row
wks.userparam2 = 1;

loop (j,1,wks.ncols)
{
	//calculate Mean and show 3 significant digits
	wcol(j)[Mean]$ = $(mean(wcol(j)),*3); 
	//show 0 decimal places for Size
	wcol(j)[Size]$ = $(count(wcol(j),1),.0);
}

As you can see from the code above, you can use the user-defined parameter row’s name as cell row index to access it directly.

If you want to show it immediately after import and dynamically update with change of data, and save the script with the worksheet for future uses, here are the steps:

  1. Choose Worksheet: Worksheet Script… menu.
  2. Copy the Script above into the big box in the dialog.
  3. Check After Script and Upon Changes in Ranges(s) (space separated) checkboxes.
  4. Enter 1:end as the range so changes in any column will trigger the script.
    doc2337_wks_script_db
  5. Click Do It or Update button.
  6. Choose File: Save Template As… and give a meaningful template name, e.g. Mean_Size_in_Label.
  7. Choose File: Recent Book: or use Open Template button to load it and enter some data to see the update in Mean and Size rows.
    doc2337_mean_size_label

Leave a Reply

Your email address will not be published. Required fields are marked *