Why do I receive "Machine_Problem_8" requires more input arguments to run?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
% 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
0 comentarios
Respuestas (1)
Les Beckham
el 25 de En. de 2022
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").
0 comentarios
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!