Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab. Need help fixing code The user must be allowed to perform these actions

ID: 3662842 • Letter: M

Question

Matlab. Need help fixing code

The user must be allowed to perform these actions in any order until the user decides to exit the program.

You must test that all input provided by the user are valid. If user gives invalid input, provide error message and allow user to correct his/her input.

It is not possible to choose anything other than load data FIRST. If user attempts to do this. Display error message stating that it is not possible.

I need help fixing the code. Thanks!

mainscript.m

disp('Hi. What would you like to do?');
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');

count=0;
switch mypick
case 1
disp('You have chosen to load a data.')
uiwait(msgbox({'You will be asked to enter' 'a month number.'...
'Here are your choices:' '1 = January' '2 = February'...
'3 = March' '4 = April' '5 = May' '6 = June', '7 = July'...
'8 = August' '9 = September' '10 = October' '11 = November'...
'12 = December'}));
prompt={'Enter Month Number'};
name = 'Month Number';
defaultans = {'1'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
mntNo=cell2mat(answer);
mntNo=str2double(mntNo);
[sunData, sunTimeMatrix]=loadSolarData(mntNo)
[windData, windTimeMatrix] = loadWindData(mntNo)
count=count+1;
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');
  
case 2
if count==0;
errordlg('No data loaded','File Error');
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');
else
disp('Plot average day')
plotAverageDay(sunData,sunTimeMatrix,windData,windTimeMatrix)
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');
end
  
case 3
if count==0;
errordlg('No data loaded','File Error');
else
disp('Plot Daily Values')
plotDailyValues(sunData,sunTimeMatrix,windData,windTimeMatrix)
end
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');

case 4
disp('Good Bye!') exit program
  
otherwise
disp('You have closed the menu screen!')
end
end

Explanation / Answer

disp('Hi. What would you like to do?');
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');
count=0;
switch mypick
case 1
disp('You have chosen to load a data.')
uiwait(msgbox({'You will be asked to enter' 'a month number.'...
'Here are your choices:' '1 = January' '2 = February'...
'3 = March' '4 = April' '5 = May' '6 = June', '7 = July'...
'8 = August' '9 = September' '10 = October' '11 = November'...
'12 = December'}));
prompt={'Enter Month Number'};
name = 'Month Number';
defaultans = {'1'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
mntNo=cell2mat(answer);
mntNo=str2double(mntNo);
[sunData, sunTimeMatrix]=loadSolarData(mntNo);
[windData, windTimeMatrix] = loadWindData(mntNo);
count=count+1;
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');
  
case 2
if count==0;
errordlg('No data loaded','File Error');
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');
else
disp('Plot average day')
plotAverageDay(sunData,sunTimeMatrix,windData,windTimeMatrix)
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');
end
  
case 3
if count==0;
errordlg('No data loaded','File Error');
else
disp('Plot Daily Values')
plotDailyValues(sunData,sunTimeMatrix,windData,windTimeMatrix)
end
mypick=menu('What would you like to do?','Load data', 'Plot average day',...
'Plot daily values','Exit the program');

case 4
disp('Good Bye!')
exit program
  
otherwise
disp('You have closed the menu screen!')
end