How do i keep the menu from disappearing, even when i push one of the menu buttons?

4 次查看(过去 30 天)
This is my script and i would like that the menu stays on screen even if I push one of the menu buttons and disappearing when i push the fourth case, using while loop.
This is my script:
Valuta = menu('Historiske valutakurser','NOK SEK DKK 1960-2014',...
'NOK SEK DKK CNY 2005-2014','Lagre figur (.jpg)','Avslutt');
while Valuta
switch Valuta
case 1
figure(1)
plot(x,NOK,x,SEK,x,DKK,'y')
grid on
title('Valutakurser fra 1960 til 2014')
legend('Norske kroner','Svenske kroner','Danske kroner')
ylabel('Valutakurs')
xlabel('Årstall')
axis([1960,2014,70,140])
case 2
figure(2)
plot(x2,NOK2,x2,SEK2,x2,DKK2,x2,CNY)
grid on
title('Valutakurser fra 2005 til 2014')
legend('Norske kroner','Svenske kroner','Danske kroner','Kinesisk Yuan')
ylabel('Valutakurs')
xlabel('Årstall')
axis([2005,2014,75,120])
hold on
case 3
saveas(figure(2),'stud234099.jpg')
hold off
case 4
break
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2015-10-5
You cannot do that using menu(): menu is coded to always wait for a response and to always delete the figure afterwards.
You could use inputdlg() with an options structure of 'WindowStyle' 'normal'. However if you do so then it will return empty values from the call and you would need to figure out how to ask the figure for the current result.
You should consider using uicontrol of style pushbutton, or consider a uicontrol of style listbox, or consider using a uibuttongroup to manage a number of uicontrol style radio .
Note: your code appears to allow the user to save figure 2 before anything has been drawn to figure 2. If the user never selects the second option then figure 2 will be empty when you go to saveas() it for the third option.
  1 个评论
Walter Roberson
Walter Roberson 2015-10-8
It is not possible to do what you want while you use menu(). menu() is specifically designed to prohibit the user from having control until they have answered the question, and designed to delete the menu afterwards. You cannot do it with menu().

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by