Jump to main content

##

# 3.9.11 UTIL_2DPlotRead

## C

    /* Read from 2D plot */
     float32_t UTIL_2DPlotRead( tUTIL_2DPlot_s * const p2DPlot,  const float32_t xPoint )

## Summary

This function reads the data from 2D plot .

## Description

This function reads and interpolates the output (y) value corresponding to a given input (x) from a 2D plot. If the x-value is outside the range of the plot, the function returns the y-value of the nearest boundary point.

## Precondition

None.

## Parameters

Param | Description
--- | ---
p2DPlot | Pointer to the 2D plot structure from which the y-value is to be read.
xPoint | The x-value for which the corresponding y-value needs to be interpolated.

## Returns

Returns the interpolated y-value corresponding to the input x-value

## Example

    // Define a structure for 2D points
    typedef struct
    {
        float32_t x;
        float32_t y;
    }tUTIL_2DPoints_s;

    // Define a structure for 2D plot
    typedef struct
    {
        uint8_t dataPoints;
        tUTIL_2DPoints_s  points[10u];
    }tUTIL_2DPlot_s;

    // Declare a structure for 2D plot

    tUTIL_2DPlot_s 2DPlot = {
        .dataPoints = 3,
        .points = {
            {1.0f, 2.0f},
            {3.0f, 4.0f},
            {5.0f, 6.0f}
        }
    };

    float32_t xValue = 4.0f;
    float32_t yValue;

    /* Read from 2D plot  */
    yValue = UTIL_2DPlotRead(&2DPlot, xValue);

## Remarks

None.