Why do I receive "Machine_Problem_8" requires more input arguments to run?

% longestword.m
function out = Machine_Problem_8(Heat, Lakers, Warriors)
% Matlab function that takes as inputs 3 words and return the word with
% the most number of characters (and the first in the list when they
% have the same length)
% set out to word1
out = Heat;
% strlength is used to return the number of characters in input string
% if number of characters in word2 > out, set out to word2
if(strlength(Lakers) > strlength(out))
out = Lakers;
end
% if number of characters in word3 > out, set out to word3
if(strlength(Warriors) > strlength(out))
out = Warriors;
end
end
%end of longestword.m

Answers (1)

How did you call your function? You can't just press the "Run" button in the editor to call a function that expects input arguments.
Also, Matlab expects the filename of a function mfile to match the name of the first function in the file, so either rename the longestword.m file to Machine_Problem_8.m or change the function name to longestword (I would recommend the latter).
I would also recommend using generic names inside the function. In other words, replace Heat with word1, etc. Then you would call the function like this at the command line: longestword("Heat", "Lakers", "Warriors").

Categories

Products

Release

R2021b

Asked:

on 23 Jan 2022

Answered:

on 25 Jan 2022

Community Treasure Hunt

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

Start Hunting!