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.
0 个评论
回答(1 个)
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 ()
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Delaunay Triangulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!