Unrecognized function or variable 'guess_my_number'.

How I can solve the function?
I'm doing the course now and in the lesson number 5 we have a simple exercise with the function called 'guess_my_number', but when I'm trying to use it, Matlab says the next:''Unrecognized function or variable'' or ''Not enough input arguments''. I'm using the free trial of Matlab R2020a.
function guess_my_number(x)
if x == 2
fprintf('Congrats! You guessed my number!\n');
end

 Accepted Answer

Matlab says the next:''Unrecognized function or variable'' or ''Not enough input arguments''
Those are two unrelated error messages. The first one is telling you that the file containing the function is not on Matlab's path. Use addpath(...) so matlab has access to the file. (see help addpath if needed). Or it might mean that the a variable or function name was misspelled.
The second error message means that Matlab does recognized the file but not enough input arguments were provided. The function looks like it has 1 input so when you call the function from the command window or from another function or script, you need to provide it with a value such as ,
guess_my_number(20)

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!