Why do I get the error "Unrecognized function or variable" with this
246 views (last 30 days)
I'm trying to create a function that gives the value of y given any x. I have two matrixes (speed1 and time) that shows corresponding values for the x- and y-axis, so I need my function to calculate the value of y given any x. To do this I have made the following:
But I get an error saying: "Unrecognized function or variable 'time'" (the same for speed1), and I don't understand what's wrong. The matrixes I used are saved matfiles that I have on my computer so to use them I first import the data so I have them in workspace and they work if I don't use them in a function.
What can I do to resolve the issue?
(edit: fixed the variable names since I wrote i wrong the first time)
madhan ravi on 14 Feb 2021
Edited: madhan ravi on 14 Feb 2021
I don't know why you deleted your question and changed your name.
1) Why do you name a variable as the same name of a FUNCTION.
2) Call a function instead of pressing the green button to run a function which expects input arguments.
function v = SPEED(t)
x = speed
y = consumption
v = interp1(x, y, t);
More Answers (1)
Image Analyst on 14 Feb 2021
What is time? Your function does not know because you did not pass it in. ALso, you did not pass in speed1 so it won't know that that is and won't be able to assign it to y. Why do you think your function should know what these are unless you pass them in? It won't, so they are "undefined" and the error message tells you that.