How do I call upon a function in another function?

3 次查看(过去 30 天)
This is what I have:
function [Output] = Jamiesonlab5 ()
Result=input('Please press any key to roll the dice, press Q or q to quit program: ', 's');
if (Result == 'q' || Result == 'Q')
fprintf('program terminated')
else
X=rdmInt();
end
Output=getPhrase();
end
function [TextI] = num2txt (I)
if I==1
TextI='one';
elseif I == 2
TextI = 'two';
elseif I == 3
TextI = 'three';
elseif I == 4
TextI = 'four';
elseif I == 5
TextI = 'five';
else
TextI = 'six';
end
end
function [i] = rdmInt ()
Max=input('Max: ');
Min=input('Min: ');
x=rand();
d = x * (Max-Min+1);
e=floor(d);
i= d + Min;
end
function [] = getPhrase ()
x=rdmInt();
fileID = fopen( 'OUTPUTLAB5.txt', 'a+');
if x == 1
fprintf(fileID,'Congragulations!');
elseif x == 2
fprintf(fileID,'Way to go!');
elseif x == 3
fprintf(fileID,'Youre amazing!');
elseif x == 4
fprintf(fileID,'Fantastic!');
else
fprintf(fileID,'Wow!');
end
end
Essentially what I want to do, is get a number between 1 nd six, and output a message corresponding to that number from my first function. However, it claims I have too many output arguments at the top. Also ignore the num2text fumction, it hs no importance to my question.

回答(1 个)

Matt J
Matt J 2020-11-3
You request an output from getPhase() here,
Output=getPhrase();
but your implementation of getPhrase() does not return any output
function [] = getPhrase ()

类别

Help CenterFile Exchange 中查找有关 Delaunay Triangulation 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by