How do I call upon a function in another function?
9 ビュー (過去 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!