CLsqFit:Fit CLsqFit:GetWt

CLsqFit:GetObs


The GetObs method returns a table containing the observe value for every point in the data sample. If multichannel data is used, the function returns 1 table for each data channel. The returned table contains CLsqFit:GetNumPts() values. To get the observed value of a single point, use GetPtObs.

Syntax

tObs = CLsqFit:GetObs( nChannel* )

tObs1, tObs2, tObs3, tObs4 = CLsqFit:GetObs()

Remarks

Two forms are provided with a different number of return values. If the point uses single-channel data (i.e., typical numeric data) or you specify the channel, then a single table is returned. If the point involves multi-channel data, up to 4 tables will be returned. The number of tables returned is determined by the SetNumChannels method which was used before data were added to the fit.

Examples

The following script creates an array (a table) containing the index of every point having an observed value < -2.5. Observations metting this condition will be stored into an array (a lua table) containing their index and value, which will then be printed at the end of the script.

Note that the first for loop uses ipairs() to access the integer index of each point, starting at index 1. However, ipairs expects a continuous integer sequence with no "holes", and it stops iterating when the first nil index is found. This owrks since all points are stored in sequential integer array indices. Each point discovered with the value below -2.5 is entered into a storage table with its index and its value, hence that table will have "holes" (nils) in the continuous sequence of indices. Therefore, the second loop iterates using pairs, rather than ipairs, since pairs finds everything in the table and ignores the holes in the integral index values. The result should find points at indices 1 and 4.

local L = CLsqFit:new()

-- create a CLsqFit object

L:SetNumCoefs( 2 )

-- set 2 coefficients to fit a line to single channel data

L:AddPt( -1.5, -5.15 )

-- add points

L:AddPt( 4.3, 8.3 )

 

L:AddPt( -0.5, 12.5 )

 

L:AddPt( 2.5, -4.1 )

 

L:Fit()

-- Fit the line

local tObsLow = {}

-- create a table for the high obs values

for k,obs in ipairs( L:GetObs() ) do

-- loop over all points k having observed value obs

  if obs < -2.5 then tObsLow[k] = obs end

-- tObsLow hld the next point fond

end

 

for k,obs in pairs( tObsLow ) do

-- use pairs to catch every non-nil index k

  Printf( "PtObs[%d] = %lg\n", k, obs )

-- list the point

end

 

Related Topics

CLsqFit class, GetPtWt, SetPtWt, AddPtWt, FindPt, GetX, GetPtObs