CLsqFit:GetPtX
The GetPtX method returns the values of the independent variables for an existing sample point. The value(s) are returned in a lua table.
tableX = CLsqFit:GetPtX( nIndex, nDimension* ) |
This method returns a lua table, even if the sample points have only 1 independent variable, or "basis dimension". The variables are then accessed as elements [1], [2], and so on. The number of elements in the table equals the number of basis dimensions used in the fit. Since Mira supports up to 10 dimensions, the table may have 1 to 10 elements. To make the script more general, you can get the number of elements using the GetBasisDim method.
The GetPtX method uses the index of the target point. The value of nIndex must either be known from the order that points were added to the sample, or by matching the target point's values using FindPt.
The following example illustrates how to change the x coordinate of an existing point. The target point's index is found by matching its values:
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetNumCoefs( 2 ) |
-- set 2 coefficients |
|
-- add a point for x = 3.5, y = 5.15, weight = 1 |
|
-- add more points |
L:Fit() |
-- Fit the line |
|
-- do something with the fit results |
n = L:FindPt( 3.5, 5.15 ) |
-- find the point (if we don't know it was index 1) |
|
-- coordinate(s) returned in table t |
|
-- add 0.1 to the first index of the table (x coordinate) |
|
-- send the table to replace the 1st coordinate value |
L:Fit() |
-- get a new fit result using the new value |