MATLAB Answers

Put workspace data into menu and prompt someone to select it

39 views (last 30 days)
Homework Question:
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.
days1= string(Days);
select_day1 = menu('Please select a day',days1(:));
ice1 = string(Ice);
select_loactionID = menu('Please select location',LocationID(:));
How do i get it to load ice based on the day and location chosen


Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 2 Feb 2020
Edited: Image Analyst on 2 Feb 2020
Capture their button number into a variable then use it somehow
load ('MA2_data.mat');
dayButton = menu('Please select a day',string(Days));
locationButton = menu('Please select a location',LocationID);
chosenDay = Days{dayButton};
chosenLocation = LocationID{locationButton};
Ice = 0; % whatever you do to get its value..................
fprintf('On Day %s, at location %s, the ice thickness was %0.4f [m]', chosenDay, chosenLocation,Ice)


Show 3 older comments
Image Analyst
Image Analyst on 2 Feb 2020
Sorry - it was untested because I had not taken the time to download the mat file, but since you seem to have found a problem, I did. But I'm sure you're a smart enough engineer to have already made the corrections, but here they are anyway:
s = load ('MA2_data.mat')
Days = s.Days
Ice = s.Ice
LocationID = s.LocationID
dayButton = menu('Please select a day', string(Days));
locationButton = menu('Please select a location', LocationID);
chosenDay = Days(dayButton)
chosenLocation = LocationID{locationButton}
chosenIce = Ice(dayButton, locationButton)
fprintf('On Day %d, at Location %s, the ice thickness was %0.4f meters.\n', chosenDay, chosenLocation, chosenIce)
Alex Doan
Alex Doan on 2 Feb 2020
Ty lol and it's my 1st year learning matlab so I'm not that smart ?
Image Analyst
Image Analyst on 2 Feb 2020
No problem, but make sure you read that link about cell arrays. It will give you a good intuitive idea of how to work with them. Also, can you Accept the answer if we're done here? Thanks in advance.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!