How to attribute numeric values to a function?

1 回表示 (過去 30 日間)
claudio
claudio 2016 年 5 月 14 日
編集済み: claudio 2016 年 5 月 30 日
Hello everyone!
MatLab does not accept numeric attributes directly. So, how can it be done?
Thank you!
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 14 日
Your question is not clear

サインインしてコメントする。

回答 (2 件)

Jos (10584)
Jos (10584) 2016 年 5 月 14 日
Why store the result in a different variable
V = input('Enter a number: ') ;
switch (V)
case 1
out = sin(2) ;
case 2
out = cos(1) ;
otherwise
out = NaN ;
end
Alternatively you can store anonymous functions in a cell array, but if I were you I would avoid road that for now.

Image Analyst
Image Analyst 2016 年 5 月 14 日
編集済み: Image Analyst 2016 年 5 月 14 日
Try this, more GUI-based, nicer way of doing it:
buttonCaptions = {...
'function1=cos(1.0498*8000);',...
'function2=sin(0.6584*8000);',...
'function3=sin(0.6584*8000);',...
'function4=sin(0.6584*8000);',...
'function5=sin(0.6584*8000);',...
'function6=sin(0.6584*8000);',...
'function7=sin(0.6584*8000);',...
'function8=sin(0.6584*8000);',...
'function9=sin(0.6584*8000);'}
buttonNumber = menu('What function do you want to run?', buttonCaptions)
switch buttonNumber
case 1
result = cos(1.0498*8000);
case 2
result = cos(1.6584*8000);
case 3
result = cos(1.0498*8000);
case 4
result = tan(1.6584*8000);
case 5
result = acos(1.0498*8000);
case 6
result = cosd(1.6584*8000);
case 7
result = asin(1.0498*8000);
case 8
result = sind(1.6584*8000);
case 9
result = atan2d(1.0498*8000);
end
message = sprintf('The result of the function is %f', result);
uiwait(helpdlg(message));
Obviously make changes as needed.

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by