How do I keep my popup menu form disappearing

2 views (last 30 days)
Hello, I made a menu i Matlab and I want the menu not disappearing when i click on one of the cases using while loop, and 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])
case 3
saveas(figure(2),'stud234099.jpg')
hold off
case 4
break
end
end

Answers (1)

Walter Roberson
Walter Roberson on 9 Oct 2015
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.
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().

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!