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
 Get/Set DataRange-Rows by axis 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

hofmaale

20 Posts

Posted - 01/14/2014 :  10:51:25 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi there.

I thought this youd be an "easy to solve" problem - however up to now (that is, 4 Hours of searching) - I failed.

The goal is to automate integration of multiple datasets with the same parameters, that is, the same start- and end-values in X-Axis-Coordinates.

I managed to write an OriginC-Script to integrate all curves in the active graph and write the results to a new worksheet.

The Script uses GetDataMarkers to get the Start & End Row-Index of the currently selected curve, so that the user can visually select the data to integrate.

But, as there is no easy relationship between row-index and the x-column-value at this index, the integration is only valid for the currently selected curve (measurement data starts at different time-values (X), but hast to be integrated e.g. from 0盜 to 40盜).

So, what I'm trying to do is: get X-Axis-Values for the position range selected, and calculate the rows to select for each curve being integrated.

I could retrieve all data from the selected curve's X-Column, look up the value at the given index and then calculate the new index by retrieving all Data for all the other curves - but I think there must be some functionality like this already present in Origin?

When manually integrating the data, the range used looks something like this: [Book]Worksheet!("A":"B")[x0.7:40.7], with the two extends of the integration 0.7 and 40.7 in X-Axis coordinates.

However, I'm not able to reproduce this when creating range-objects by instantiating DataRange, DataRangeEx or XYRange. The Reference tells me that DataRangeEx can be used to initialize a range by using a similar syntax, but it does not seem to work as I thought it would (see http://ocwiki.originlab.com/index.php?title=Category:DataRangeEx_%28class%29)

Do you know any possibility to initialize Range-Objects by Coordinate-Values (not row-indices)?

Thanks in Advance

Alexander



---------------
Origin Ver. and Service Release: 9.1.0G Sr1
Operating System: Win XP

Castiel

343 Posts

Posted - 01/14/2014 :  11:11:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I think you got things too complicated...just get data from a DataRange and perform the integration:
BOOL DataRange::GetData( vectorbase * pData, int nIndex )
and
int ocmath_numeric_integral( double x, double * py, uint npts, const double * pxData, const double * pyData )

You may want to take a close look at the latter one.



妾+   午旦  妹罕妾  妾伊    用仇  妾/     岫ㄞ
 妾京用 仍巨  件 侈   件戶' 甘岫平   /欠  白岫妹
   併             艮          岫  奈 白   岫
                              岫
Go to Top of Page

hofmaale

20 Posts

Posted - 01/15/2014 :  05:11:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

thanks for your reply.

ocmath_numeric_integral would replace my call to the integ1-XFunction, but still I would have to slice down the data to the relevant portion by hand (the measurement covers some 500盜, containing all rubbish except 40盜 of relevant data somewhere in the middle).

Although, as for the way you suggested I'll need the data in a vector anyway, this would probably produce no significant overheat and is probably easier to implement as calling the XFunction.

I'll check that!
Go to Top of Page

hofmaale

20 Posts

Posted - 01/15/2014 :  09:31:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
After another hour I succeeded in doing what I wanted.

ocmath_numeric_integral really is easier to use compared to the XFunctions called from C++; however I could not find any way to automatically generate Ranges from Axis-Coordinates (the functions ends it's integration at a given x-Value in axis coordinates, but it starts at position 0 in the input vector, which might not be 0 in coordinates).

This, hovever, was not as complicated as I thought it would be:

int findNearestX(Dataset &dX, double value)
{
	int startIndex = dX.GetLowerBound();
	double dif = abs(value - dX[startIndex]);
	double newDif = dif;
	for (int ii=startIndex+1; ii <= dX.GetUpperBound(); ii++)
	{
		newDif = abs(value - dX[ii]);
		if (newDif > dif)
		{
			return ii-1;
		}
		dif = newDif;
	}
	return dX.GetUpperBound();
}


See the complete script here:
http://pastebin.com/yYGbUiUa

Thanks again for the hint!

Edited by - hofmaale on 01/15/2014 09:33:17 AM
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