Interp1 command, wrong number of input arguments

9 views (last 30 days)
xc = conv(h,x);
tr = start : Ts : stop;
R = 1050;
tau = 2*R/c;
yc = interp1(xc,tt,tau,tr); % compute the received reflection
So this is part of my code and I keep getting the error, ''Wrong number of input
arguments.'' for the command interp1, not sure how to fix that.
  1 Comment
Stephen23
Stephen23 on 24 Oct 2019
Original question, in case it gets deleted again:
"Interp1 command, wrong number of input arguments"
xc = conv(h,x);
tr = start : Ts : stop;
R = 1050;
tau = 2*R/c;
yc = interp1(xc,tt,tau,tr); % compute the received reflection
So this is part of my code and I keep getting the error, ''Wrong number of input
arguments.'' for the command interp1, not sure how to fix that.

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 9 Apr 2019
Edited: John D'Errico on 9 Apr 2019
Read the help for interp1.
With 4 input arguments:
Vq = interp1(X,V,Xq,METHOD) specifies the interpolation method.
The available methods are:
The 4th argument would indicate which interpolation method you want to use.
So the question is, why are you passing in 4 numerical arguments?
xc = conv(h,x);
tr = start : Ts : stop;
R = 1050;
tau = 2*R/c;
yc = interp1(xc,tt,tau,tr); % compute the received reflection
Software does what it is programmed to do. You cannot just pass in an arbitrary number of arguments and expect it to know what you want it to do.
  2 Comments
John D'Errico
John D'Errico on 10 Apr 2019
I doubt you really did try a valid use of interp1. But it is hard to know what you did try, since you have carefully kept everything secret. Lets see.
yc = interp1(xc,tt,tau,tr);
We have xc. What size is xc? No clue, since it is just the result of a call to conv, and only you know what h and x are. EXACTLY what shape are they? Are they row vectors, scalars, column vectors?
What is tt? Here, you never even defined that variable as far as we see.
tau appears to be a scalar, maybe. But we have not been clued in to know what c is. And depending on c, tau might be anything, and various shapes. So what is tau?
What is tr? What shape is it? it is PROBABLY a row vector, depending on the values of start and stop.
So in order to help you, I would actually need to know what you are passing in. But it seems you may not even know that.
You need to learn to be more careful. When you call a function like interp1, you need to know what the arguments are for that function. You need to know what you are passing in.
The point is, SLOW DOWN. You are throwing lots of stuff around, and I have the clear impression that you sometimes don't know what is in each variable, what size they are. When you start to use a tool like MATLAB, get used to checking EVERY thing you do. Make sure that everything you do makes sense in context. Until you start doing that, you will keep on getting random results that make no sense, plus random errors much of the time.
What are you trying to interpolate? What is the dependent variable? What is the intependent variable?
Walter Roberson
Walter Roberson on 10 Apr 2019
You tried what as well? That was a copy of your same code. We are trying to understand what you expect each of the four parameters to mean to interp1(). Are you expecting one of the four values to be the value to return if extrapolation is requested, for example ?

Sign in to comment.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!