How do I use a switch statement to convert units?

For example, if I want to convert from grams to pounds or grams to kilograms. Like use the switch statement to display a menu that will require an input value of grams to convert to kilograms or pounds as the two options and display the answer.

1 件のコメント

James Tursa
James Tursa 2015 年 4 月 29 日
Please post what you have done so far and we can comment on it and make suggestions.

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

 採用された回答

Joseph Cheng
Joseph Cheng 2015 年 4 月 29 日
編集済み: Joseph Cheng 2015 年 4 月 29 日

0 投票

Well you probably wouldn't want to use a switch statement to display a menu. You'd probably use something like a questdlg(), inputdlg() or generate your own Gui to get what the original unit is and what you're converting to. this will give you inputs for two different switch statements. First switch statement would then know which unit you're starting in and then convert to your pick of a standard (lets say grams or meters depending on the unit). Then your second switch statement would be what you're converting to. and since you've picked a standard unit you know where you're starting from. That way you don't need to create each possible conversion that does lbs->gram, lbs-> kg, lbs->oz.

その他の回答 (0 件)

カテゴリ

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

質問済み:

2015 年 4 月 29 日

編集済み:

2015 年 4 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by