Undefined function or variable??

When calling a function in a script, I keep getting the same "Undefined function or variable 'input3'". The function is described below :
function results = f(input1,input2, input3, input4)
....
...
Later on in function, I use input3 and get the error message "Undefined function or variable 'input3'". I checked the function, script and everything and there are no typos. I don't understand how matlab is not recognizing the variable when it is clearly an input into the function. Help would be appreciated.

답변 (1개)

madhan ravi
madhan ravi 2020년 6월 22일

0 개 추천

input1 =1;
input2 = 2;
input3 = 3;
input4 = 4;
results = f(input1,input2, input3, input4) % this is how you call a function, assuming that the function is saved in a file called “f.m” if you’re using versions before 2016b

댓글 수: 8

John Madsen
John Madsen 2020년 6월 22일
I am calling the function correctly. input1,input2,input4 are all recognized but input3 is not and i get an error message. I am currently using matlab R2017a.
madhan ravi
madhan ravi 2020년 6월 22일
Show how your calling the function and the value of input3 using a screenshot.
madhan ravi
madhan ravi 2020년 6월 22일
How’s this even related to the original question you asked??
John Madsen
John Madsen 2020년 6월 22일
I was trying to phrase the question in more general terms that weren't super specific to my particular project. Would you still be able to help me?
madhan ravi
madhan ravi 2020년 6월 22일
Sure, attach your file.
John Madsen
John Madsen 2020년 6월 22일
Do you need my file to help? which file in particular? I would prefer to not post the .m file
Walter Roberson
Walter Roberson 2020년 6월 23일
Does madsen_plot_ROC have an evalin('caller') or assignin('caller') in it?
If not then copy the madsen_plotROC portion of the call from two lines above, pasting it over the call on that line. We know the line two above worked because we had to get through it to get to the (3,2,4) plot. Doing the copy/paste would remove the possibility of an invisible typing mistake that is not obvious due to the font.
John Madsen
John Madsen 2020년 6월 23일
Thank you so much! That helped. Still don't know exactly what was going on there but it works now so thank you.

이 질문은 마감되었습니다.

질문:

2020년 6월 22일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by