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.
tObs = CLsqFit:GetObs() tObs = CLsqFit:GetObs( nChannel ) tObs1, tObs2, tObs3, tObs4 = CLsqFit:GetObs() where |
nChannel is the optional channel to select for multi-channel data.
tObs is a Lua table containing the observed valeus assigned all points.
tObs1, tObs2, tObs3, tObs4 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.
Two formats 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.
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.
|
-- create a CLsqFit object |
|
-- set 2 coefficients to fit a line to single channel data |
|
-- add points |
|
|
|
|
|
|
|
-- Fit the line |
|
-- create a table for the high obs values |
|
-- loop over all points k having observed value obs |
|
-- tObsLow hld the next point fond |
|
|
|
-- use pairs to catch every non-nil index k |
|
-- list the point |
|
|