The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Row number of a median value
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

thomsen01

Austria
22 Posts

Posted - 04/28/2014 :  09:52:30 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 9.1.0G (32-bit) SR2, Win7

Hello!

How can I get the row number of a median?
For example I have a datasheet with 1 column:
2
3
1
6
7
8
3
with the function:
db=median(col(1)[1:5],2);
db=;
I can get the median of the first 5 rows and it's "3", but how can I also get the row number (in this case "2")?
Thanks for your help!

Thomsen

lkb0221

China
497 Posts

Posted - 04/28/2014 :  11:40:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

If you can sort the dataset first, function index can be used.
http://www.originlab.com/doc/LabTalk/ref/Index-func

But if your data have to be non-monotonic, you may use list function to find the index when it first appears.
http://www.originlab.com/doc/LabTalk/ref/List-func


Zheng
OriginLab

Edited by - lkb0221 on 04/28/2014 12:10:47 PM
Go to Top of Page

greg

USA
1378 Posts

Posted - 04/28/2014 :  3:53:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Without sorting, if you know the median is unique, you can use this:

range raD = [Book1]Sheet1!col(2);
MedianRow = list(median(raD,1),rad);

But it's possible the median exists more than once, in which case you can use:

dataset dsIdx;
range raD = [Data1]Sheet1!2;
MedianValue = median(rad,1);
vfind value:=MedianValue ix:=rad ox:=dsIdx;
loop(ii,1,dsIdx.GetSize())
{
ty $(MedianValue) in row $(dsIdx[ii]);
}

Note that only option 1 of the Median function returns a value that is actually found in the data.
Go to Top of Page

thomsen01

Austria
22 Posts

Posted - 04/30/2014 :  09:26:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for the answers.

Unfortunately I have no possibility to sort my dataset, but the second solution by greg works fine with a few adjustments.

Thanks for your help.

Thomsen
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000