Use of Interp to Interpret Data from a Table

9 views (last 30 days)
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."

Answers (1)

Voss
Voss on 30 Jul 2023
Use interp1 instead of interp.

Community Treasure Hunt

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

Start Hunting!