CLsqFit:GetNumPtsUsed CLsqFit:GetPtX

CLsqFit:GetPt


The GetPt method returns the values of both the independent and dependent variables of a sample point. The value(s) are returned in a 1-dimensional array.

Syntax

tbl = CLsqFit:GetPt( nIndex )

bullet.gif    nIndex is the index of the point in the sample, beginning at index 1.

bullet.gif    tbl is a 1-dimensional array holding the independent variables plus the dependent variables for the point.

Remarks

The array has a total dimension of #x for the table x of independent variables, plus #obs for the table obs of dependent variables (observations). For example, if the fitting basis has 3 variables (dimensions) and numerical observations were fit, then the returned table has 3 + 1 = 4 elements. Similarly, if the fitting basis has 2 variables (dimensions) and RGB observations were fit, then the returned table has 2 + 3 = 5 elements.

The number of table elements may be obtained using the # operator, like #t, as shown in the example below. Alternatively, you can get the counts of each using GetBasisDim and GetNumChannels.

The GetPt 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 point's values using FindPt.

Example

The following example illustrates how to get the independent and dependent variables for an existing point. The target point's index is found by matching its coordinates:

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( 2 )

-- set 2 coefficients

-- add points to the fit...

 

-- add another point to the fit:

 

L:AddPt( 3.5, 5.15 )

-- add a point for x = 3.5, y = 5.15, weight = 1

-- add more points to the fit

 

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)

if n < 1 then Exit("bad point") end

-- point index < 1 means point not found

t = L:GetPt(n)

-- Get the coordinates, returned in array t

Printf("nvalues = %d\n", #t)

-- Get the number of table elements

-- list all the values for point n

 

for i = 1, #t do

 

  Printf("%lg\t", t[i] )

-- list each value of thereturned table

end

 

-- Alternately, list the table like this:

 

list(t)

 

Related Topics

CLsqFit class

GetPtX

GetPtObs

AddPt

FindPt

 


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.