Menu/Trig help

2 ビュー (過去 30 日間)
Collin Kerr
Collin Kerr 2016 年 3 月 10 日
回答済み: Star Strider 2016 年 3 月 10 日
clc
A = input('Opposite angle: ');
B = input('Adjacent angle: ');
C = input('Hypotenuse angle: ');
E = (B/C); %Cosine
F = (A/C); %Sine
%S(o/h)C(a/h)T(o/a) SoaCahToa
T = menu ('Which trig sign do you want to use.' ,'sin', 'cos', 'tan', 'cot', 'cosec', 'sec');
if T == 1;
(A/C)
elseif T == 2;
(B/C)
elseif T == 3;
(A/B)
elseif T == 4;
(B/A)
elseif T == 5
(C/A)
elseif T ==6
(C/B)
end
X = sprintf(('For a triangle of sides H, O and A,(Needs to be the answer picked from menu)
Does anyone know how once I pick from the menu, to make that answer a variable so I can use for sprintf like %s or something. Would be a huge help.

採用された回答

Star Strider
Star Strider 2016 年 3 月 10 日
Use a cell array of strings. You can address the as any other array.
For example:
fcn_name = {'sin', 'cos', 'tan', 'cot', 'cosec', 'sec'};
T = 3;
str = sprintf('The value of %s = %.4f\n', fcn_name{T}, 0.3)
str =
The value of tan = 0.3000

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by