CLsqFit:FindPt


The FindPt method returns the index of a point based on matching its values and, optionally, its channel. If a channel is specified, then the index returned is the index of the point for that channel.

Syntax

n = CLsqFit:FindPt( x, V )

n = CLsqFit:FindPt( x, V, nChannel )

n = CLsqFit:FindPt( tableX, V )

n = CLsqFit:FindPt( tableX, V, nChannel )

n1, n2, n3, n4 = CLsqFit:FindPt( x, V )

n1, n2, n3, n4 = CLsqFit:FindPt( tableX, V )

bullet.gif    x is the coordinate for dimension 1 of the sample point.

bullet.gif    tableX is a 1-dimensional array containing n values for the n independent variables of the sample point. Use this form when the basis function takes more than 1 independent variable (i.e., the basis function uses more than 1 dimension).

bullet.gif    V is the observed value at coordinate x or coordinate vector x. When fitting single channel (numeric) data, this is a number. When fitting multi-channel (e.g., RGB) data, this is a string with the channel values separated by commas.

bullet.gif    nChannel is an optional parameter which specifies the channel to search. If omitted, all channels are searched.

bullet.gif    n, n1, n2, n3, and n4 are the indices of the point in the sample data or in the channels of multi-channel (e.g., RGB) data. The number of values returned equals the number of channels.

Remarks

The FindPt method returns the index of the target point in the sample data of the specified channel. If the channel is omitted, then the only channel, or first channel of multi-channel data, is searched. The arguments of this method are similar to that of the AddPt method except that an optional channel index may be specified.

Examples

The following example illustrates how to change the weight of an existing point. In this case, the target point's index is found by matching its values:

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( 2 )

-- set 2 coefficients

L:AddPt( 3.5, 5.15 )

-- add a point for x = 3.5 and y = 5.15

-- 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 has index 1)

if L:GetPtWt(n) > 5 then

-- if the point has weight > 5

  L:SetPtWt( n, 2.5 )

-- reduce the weight of the point to 2.5

end

 

L:Fit()

-- get a new fit result using different weights

 

The next example illustrates how to change the weight of a point having more than 1 independent variable. This requires passing the independent variables using a table:

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( {2,2,2} )

-- set 2 coefficients each for 3 independent variables

L:AddPt( {3,4,5}, 7.25 )

-- add a point with tableX = {3,4,5} and V = 7.25

-- add more points to the fit

 

L:Fit()

-- Fit the function

-- do something with the fit results

 

n = L:FindPt( {3,4,5}, 7.25 )

-- find the point (if we don't know it has index 1)

if L:GetPtWt(n) > 5 then

-- if the point has weight > 5

  L:SetPtWt( n, 2.5 )

-- reduce the weight of the point to 2.5

end

 

L:Fit()

-- get a new fit result using different weights

Related Topics

CLsqFit class, AddPt, Working with RGB data


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