T O P I C R E V I E W |
johannes.kastl |
Posted - 08/09/2013 : 08:07:12 AM Hi everyone,
I fumbled around with calculating cell values today, but got nowhere with the mean and stddev functions. I just wanted to calculate the mean of each row for three columns.
I tested further with labtalk:
range TEST=Col(A);mean(TEST)=; calculates the mean of the whole column A.
range TEST=Col(A)[1:10];mean(TEST)=;code] calculates the mean of rows 1 to 5 of column A.
But I found no way to get more than one column into the mean function, although it should accept a range as input, according to http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:Mean_%28function%29.
Same for stddev(). And the same is true for 'blocks of cells'.
Do I understand something wrong? Does mean only accept whole columns?
Or is the reason the same as for the range.getsize(), which only returns values of the first column, if the input range is a block of cells? (http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:Range_Notation&rdfrom=http%3A%2F%2Fwiki.originlab.com%2F%7Eoriginla%2Fwiki%2Findex.php%3Ftitle%3DLabTalk%3ARange_Notation%26redirect%3Dno#Methods_of_Range)
Thanks in advance, Johannes
Origin Ver. and Service Release (Select Help-->About Origin): 9.0.0G SR2, Operating System: WinXP |
6 L A T E S T R E P L I E S (Newest First) |
AlexD2 |
Posted - 01/14/2014 : 4:31:50 PM Beautiful!
Thank you!
AlexD2 |
greg |
Posted - 01/14/2014 : 4:03:31 PM The -v switch is new in Origin 9.1.
http://wikis/ltwiki/index.php?title=LabTalk%3ARange_Notation#Option_Switch_-vOption_Switches
The range points to data - which need not be contiguous - and then acts like a single dimension array of data stored in column major order.
The range can currently only be used in an X Function where the Input type is vector. Stats is such an X Function, so stats of a row can easily be determined:
row = 7; range -v raRow = 1[row]:end[row]; stats raRow; stats.mean=;
Here is a non-contiguous example: newbook; loop(ii,1,5) { wcol(ii)=data($(ii),$(ii+5)); } range -v raV = (col(1)[1:3],col(3)[2:4],col(5)[3:6]); stats raV; stats.=;
|
AlexD2 |
Posted - 01/12/2014 : 11:45:16 AM One can apparently also use the -v option switch of the range declaration:
range -v rRow = 1[3]:8[3]; // Defines a range (vector type?) rRow // over the 3rd row between columns 1 and 8 mean(rRow)=; // Gives the expected row mean
Not sure how general is this trick though...
If someone can clarify (or give a link) for the subtle difference between e.g. dataset, vector, and range defined with the -v switch, that would be much helpful...
Many thanks,
AlexD2 |
johannes.kastl |
Posted - 08/16/2013 : 05:07:07 AM Hi Greg,
thanks for clarifying.
It would be nice if the difference between vectors and ranges in general would be explained somewhere in the help or the wiki (or have I just not found it?).
And the Just-one-column-thingy should be in the explanations for mean, stddev etc., e.g. here: http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:StdDev_%28function%29 http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:Mean_%28function%29 http://wiki.originlab.com/~originla/ltwiki/index.php?title=Script:LabTalk-Supported_Functions http://ocwiki.originlab.com/index.php?title=XFProgramming:Using_Range_in_X-Function
Especially as the descriptions for mean() and stddev() are pretty short... ;-)
Regards, Johannes |
greg |
Posted - 08/15/2013 : 4:19:04 PM mean( ), stddev( ), etc. all take vector arguments which means they are limited to a single dimension array, so any range you declare with the intent of passing as an argument to these functions must be to a single column (or dataset) or sub-range of that column.
Origin does not outright reject a multi-column range and instead returns the value for the first column in the range. Odd, but there you have it.
If all you need are mean and SD for a contiguous block of cells, you can use the stats X-Function:
range raMC = 2[10]:6[35]; // Range from column 2 row 10 to column 6 row 35 stats raMC; ty Mean is $(stats.mean) with SD of $(stats.sd);
|
johannes.kastl |
Posted - 08/12/2013 : 09:09:54 AM Christy,
thanks for your answer.
I should have been more clean in my first post. I already know of some ways to get the row statistics. Disadvantage for rowstats is that it can't be automatically recalculated, which is possible by using either "Calculate values" or by using the function in the Statistics-Menu.
I was just wondering why mean() and stddev() do not accept a valid range as input. If there was - an error in my statements or - an error in the description to these functions (and they do not accept all ranges as input) or - a bug in Origin, which leads to this behaviour.
Sorry for the confusion.
Regards, Johannes |
|
|