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

tblObs = CLsqFit:GetObs()

tblObs = CLsqFit:GetObs( nChannel )

tblObs1, tblObs2, tblObs3, tblObs4 = CLsqFit:GetObs()

bullet.gif    nChannel is the optional channel to select for multi-channel data.

bullet.gif    tlObs is a 1-dimensional array containing the observed values.

bullet.gif    tblObs1, tblObs2, tlObs3, tlObs4 are tables of observe valus assigned to points that have multi-channel (e.g., RGB) values. The number of tables returned equals the number of channels.

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.

Example

The following script creates a table containing the index of every point having an observed value < -2.5. Observations metting this condition will be stored into an a 1-dimensional array 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.

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( 2 )

-- set 2 coefs 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

tblObsLow = {}

-- 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 tblObsLow[k] = obs end

-- tObsLow hld the next point fond

end

 

for k,obs in pairs( tblObsLow ) 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


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