Use of Interp to Interpret Data from a Table

Hi,
I have a simple table (in the form of 2D array) in which I would like to setup as a function, i.e., @(x), to extract data from by interpolation.
For example:
a = [1 2; 2 3; 3 4]; % This is my table data
I want to be able to say fn(2) and would get the value of that by interpolating from the data in 'a.'
So what I would do is the following:
fn = @(x)interp(a(:,1),a(:,2),x); % Define my function
So 'fn' now is a function that represents the data in the array where its to be evaluated at 'x.' The function to output the value of the function from a(:,2).
The above setup is done in MATLAB but it gives the following error:
"Expected r to be integer-valued."
"validateattributes(r,{'numeric'},{'>=',1,'finite','integer','scalar'},'interp','r');"
How so? I appreciate your help.
Note: I already installed "Signal processing toolbox."

Risposte (1)

Voss
Voss il 30 Lug 2023
Use interp1 instead of interp.

2 Commenti

You might also want to enable extrapolation in the interp1 call
Thank you @Voss and @Walter Roberson. Great comments.

Accedi per commentare.

Categorie

Scopri di più su Interpolation in Centro assistenza e File Exchange

Richiesto:

il 29 Lug 2023

Commentato:

il 31 Lug 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by