How do I call upon a function in another function?

조회 수: 3 (최근 30일)
John Jamieson
John Jamieson 2020년 11월 3일
답변: Matt J 2020년 11월 3일
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