Dialog boxes to calculate functions

I am trying through the code below, to get a code that calculates separately arcsine, arrcos and natural Logaritm, by the user putting in an argument x. Then i want it to write out the answer in a msgbox.
I.e how do i get this conditional to what i chose from the three functions? If or what?
choice = menu('Choose an operation','arcsin', 'arccos', 'natural logarithm')
prompt = ('insert an argument: ')
answer = inputdlg(prompt)
h = msgbox(answer)

回答 (1 件)

DGM
DGM 2021 年 4 月 10 日

0 投票

You'll get a numeric output from the menu call. Just do a switch-case structure, and calculate the answer using the corresponding function.
choice = menu('Choose an operation','arcsin', 'arccos', 'natural logarithm')
prompt = 'insert an argument: '; % don't need parentheses
arg = inputdlg(prompt); % the argument isn't the answer
arg = str2num(arg{:}); % convert it to numeric from cell
switch choice
case 1
answer = asin(arg);
case 2
% other thing
case 3
% other thing
end
then just display the answer

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

タグ

質問済み:

2021 年 4 月 9 日

回答済み:

DGM
2021 年 4 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by