Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Menu Gui - how to have the menu box always displayed

Asked by Chris on 29 Mar 2012

I have the following function:

function menu_plot_results(Data,Index)

option = menu('plot data',...

    'Exit',...
    'Close All',...
    'aaaa',...
    'bbbb',...
    'cccc');

switch option

    case 1 %Exit
    case 2 %Close All
    case 3 %aaaa
    case 4 %bbbb
    case 5 %cccc
end

cases 3-5 create plots of data. Once the figures are created, I would like the menu to re-appear, so that additional plots can be created.

Thanks

Chris

0 Comments

Chris

Tags

Products

No products are associated with this question.

3 Answers

Answer by Matt Tearle on 29 Mar 2012
Accepted answer

Unfortunately [voice = Morbo] menu does not work that way [/voice]. There are two alternatives I can think of: 1) use menu within a function called from a wrapper/control function, or 2) write an actual gui yourself. If you take route 2, you associate callbacks with each button; callback 1 will actually delete the menu window (all the others will leave there). Option 1 is less pretty, but also less work:

function menu_plot_results(Data,Index)
doagain = true;
while doagain
  option = makemenu(Data,Index);
  if option ==1
      doagain = false;
  end
end
function option = makemenu(Data,Index)
option = menu('plot data',...
    'Exit',...
    'Close All',...
    'aaaa',...
    'bbbb',...
    'cccc');
switch option
    case 1 %Exit
    case 2
        close all
    case 3
        figure
        plot(Data)
    case 4
        disp(Index)
    case 5
        disp('Hello world')
end

2 Comments

Sean de Wolski on 29 Mar 2012

My vote also goes for Route 2!

Guaranteed to be faster, easier, and less chaotic than Route 9.

Matt Tearle on 29 Mar 2012

Yeah, but so is a world war.

(Explanation for everyone else: Route 9 -> Boston-area humor...)

Matt Tearle
Answer by Sean de Wolski on 29 Mar 2012

I'm not clear on this:

You have a menu, you have it generate a figure, but then it closes and you want it to stay open?

After the plot, just have it call itself again.

function mpr(Data,Index)
option = menu('plot data',...
    'Exit',...
    'Close All',...
    'aaaa',...
    'bbbb',...
    'cccc');
switch option
      case 1 %Exit
      case 2 %Close All
          close all
      case 3 %aaaa
          figure;
          peaks;
          mpr;
      case 4 %bbbb
          figure;
          image;
          mpr;
      case 5 %cccc
          figure;
          membrane;
          mpr;
  end

Or, and this is the route I would take, don't use menu() just hard code your own GUI with a few UICONTROLS and then it doesn't have to close.

1 Comment

Matt Tearle on 29 Mar 2012

I wondered about this... This is probably fine, but I don't like the recursiveness -- if you make 15 plots, you're actually 15 function calls deep, until you finally exit and they all collapse back out.

Sean de Wolski
Answer by Chris on 30 Mar 2012

Thankyou for the replies. I used Matt's solution, worked very well.

0 Comments

Chris

Contact us