Put workspace data into menu and prompt someone to select it

5 ビュー (過去 30 日間)
Nathan Formby
Nathan Formby 2019 年 9 月 10 日
コメント済み: Nathan Formby 2019 年 9 月 14 日
How do I Load in MA2_data.mat. Prompt the user to select a day and a location based on the data provided. On the command window, output the day, location, and ice thickness [m] for that day. NOTE (avoid hardcoding): Your code should produce different results if the data for Ice changes. The options for the location or day chosen should change if the number of values in LocationID or Days changes.
load ('MA2_data.mat');
menu('Please select a day',string(Days));
menu('Please select a loaction',LocationID);
fprintf('On Day %s, at loacation %LocationID, the ice thickness was %0.4f [m]',Days,LocationID,Ice)
What letter or symbols do I place after the percent symbols?
  1 件のコメント
Adam Danz
Adam Danz 2019 年 9 月 10 日
There's lots of options.
To load data, see the load() command. (doc load, for help).
Once it's loaded you could present the days and locations in a listbox.

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

採用された回答

Adam Danz
Adam Danz 2019 年 9 月 13 日
You weren't saving the user's selections (menu outputs). The output to menu is an index of the user's selection. Use those indices in the Days, LocationID, and Ice variables.
See comments below regarding other changes.
load ('MA2_data.mat');
dayIdx = menu('Please select a day',string(Days));
locIdx = menu('Please select a loaction',LocationID);
fprintf('On Day %d, at location %s, the ice thickness was %0.4f [m]\n',Days(dayIdx),LocationID(locIdx),Ice(dayIdx,locIdx))
% %d because an integer will be placed there
% %s because a string will be place there (or char array)
% \n so the cursor goes to the next line after the message
  1 件のコメント
Nathan Formby
Nathan Formby 2019 年 9 月 14 日
Thank you for your assistance. Works like a charm.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by