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
 Forum for Origin C
 Q: getting row index of specified dataset 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

hajo_old

Germany
141 Posts

Posted - 02/21/2003 :  09:42:48 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello, all

does anyone know how I can get the rowindex of a specified dataset value.

Example:

dataset ds (size:200 elements)
now I'm looking for the maximum of the values within the dataset and get the row-index back.

analog to the function XfromYmax but as function
X from specified Y value

hope you get what I mean ....

Hajo

-- --
Dipl.-Ing. Hans-Joerg Koch
Siemens VDO, Regensburg

SVDO_Origin1

easwar

USA
1965 Posts

Posted - 02/21/2003 :  09:59:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hajo,

You can use the Data_list function, as in the example code below. The Data_list function also has a third argument to set the precision for matching the value.

Easwar
OriginLab.


void findy(string strDataset, double y)
{
Dataset dsY(strDataset);
if(dsY)
{
int iRow = Data_list(y, &dsY);
if(iRow == -1)
printf("value not found!\n");
else
printf("found %f at row index %d\n", dsY[iRow], iRow+1);
// iRow+1 for row index in GUI, iRow for row index in OC
}
else printf("invalid dataset!\n");
}


Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 02/21/2003 :  10:42:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
The Data_list function also has a third argument to set the precision for matching the value.


That's a big improvement over the LabTalk list() function, which requires an exact match.

Mike Buess
Origin WebRing Member
Go to Top of Page

hajo_old

Germany
141 Posts

Posted - 02/23/2003 :  3:33:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello, all

thanks for your replys.
I allready foud out about the Data_list() function and thought there is a function like the LabTalk list()-function as Mike pointed out. As I can get the maximum of the dataset by the max() function I know the exact value!
But I don't know the exact index, the max function found the value.

So, I would look for a function like:
[maximum, index] = max(dataset);

I tried to use the Data_list() function with several precision values and didn't get the sense in my case (I know the exact value.) because with different values for the precision parameter I got different indices for the matching dataset value!

So, the question is, what precesion is the right when knowing the exact value I'm looking for within the dataset by using the Data_list() function?

Thanks
Hajo

-- --
Dipl.-Ing. Hans-Joerg Koch
Siemens VDO, Regensburg

SVDO_Origin1
Go to Top of Page

easwar

USA
1965 Posts

Posted - 02/24/2003 :  09:43:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hajo,

Try the following function code, where -1 is used as the precision argument - see comment in code.

Easwar
OriginLab.

int findmaxindex(string strDataset)
{
Dataset dsY(strDataset);
if(dsY)
{
double dMax = max(dsY);
int iRow = Data_list(dMax, &dsY, -1);
//Pass -1 to use Origin's default internal double comparison precision
//as specified by the @ND system variable
if(iRow == -1)
printf("Error!\n");
else
printf("Max value of %f found at index %d\n", dMax, iRow+1);
return iRow;
}
}


Go to Top of Page

hajo_old

Germany
141 Posts

Posted - 02/24/2003 :  1:55:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello, Easwar

thanks for your suggestion.
This works reliably now!

Hajo

-- --
Dipl.-Ing. Hans-Joerg Koch
Siemens VDO, Regensburg

SVDO_Origin1
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