Menu pop up will not display plot
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joe Nichols
el 29 de Nov. de 2016
Comentada: Joe Nichols
el 30 de Nov. de 2016
Hello, my code will display the plot for the first option: 'Thrust SSC', however when the option: 'North American X-15' is selected the plot will not display. Why is this? (nums, txt etc are data-sets)
My code:
choice = menu('Where are you travelling from?','Mercury','Venus','Earth','Mars','Jupiter','Saturn','Uranus','Neptune'); if choice == 1; choice = menu('Where are you travelling to?', 'Venus', 'Earth', 'Mars', 'Jupiter','Saturn','Uranus','Neptune'); if choice == 1; choice = menu('How are you travelling?', 'Thrust SSC', 'North American X-15', 'Walking', 'Space Shuttle','Millenium Falcon','None of the above'); if choice ==1; [nums1, txt1] = xlsread('Planet Distance.xlsx','Distance'); [nums2, txt2] = xlsread('Planet Distance.xlsx','Velocity'); menu_title = sprintf('You are travelling from %s to %s, this journey is %d Km or %d Miles. You have chosen to travel by %s, which travels at %4d Km/h or %3d mph. You will arrive at your destination in %s hours', txt1{2,1}, txt1{2,2}, nums1(1,2), nums1(1,3),txt2{2,1}, nums2(1,1), nums2(1,2),nums1(1,2)/nums2(1,2) ); menu(menu_title,'Plot Distance v Time graph'); if choice ==1; X = [0 nums1(1,2)]; % my dependent vector of interest t = [0 nums1(1,2)/nums2(1,2)]; % my independent vector figure % create new figure plot(t, X) end;
elseif choice ==2;
[nums1, txt1] = xlsread('Planet Distance.xlsx','Distance');
[nums2, txt2] = xlsread('Planet Distance.xlsx','Velocity');
menu_title = sprintf('You are travelling from %s to %s, this journey is %d Km or %d Miles. You have chosen to travel by %s, which travels at %4d Km/h or %3d mph. You will arrive at your destination in %s hours', txt1{2,1}, txt1{2,2}, nums1(1,2), nums1(1,3),txt2{3,1}, nums2(2,1), nums2(2,2),nums1(1,2)/nums2(2,2) );
menu(menu_title,'Plot Distance v Time graph');
if choice ==1;
X = [0 nums1(1,2)]; % my dependent vector of interest
t = [0 nums1(1,2)/nums2(2,2)]; % my independent vector
figure % create new figure
plot(t, X)
end;
end;
end;
end;
1 comentario
Jan
el 29 de Nov. de 2016
Do you notice that your code is not readable? Use the "{} Code" button to fix this.
Respuesta aceptada
Jan
el 29 de Nov. de 2016
Editada: Jan
el 29 de Nov. de 2016
This is the perfect case for the debugger. Set a breakpoint in the first line, start the code and step through it line by line. Using the debugger is much more efficient than asking the forum ;-)
I guess boldly, that you forgot to catch the output of the menu command:
menu(menu_title,'Plot Distance v Time graph');
==>
choice2 = menu(menu_title,'Plot Distance v Time graph');
if choice2 == 1
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!