Menu inside menu in Matlab

536 views Asked by At

I have created a menu with different options using order 'menu'. The problem is, that I want to click one of that options and make another menu show in screen with another set of options. How can I make this kind of nested menu structure?

My code:

q=menu ('What point?:','opt1','opt2');
switch q
    case 'opt1'
        q1=menu('What subpoint?:','opt11','opt12');
        switch q1 
            case 'opt11'
            case 'opt12'
        end 
    case 'opt2'
        q2=menu('What subpoint?:','opt21','opt22');
         switch q2 
             case 'opt21'
             case 'opt22'
         end
end 
1

There are 1 answers

1
Xiangrui Li On BEST ANSWER

Your code is fine, except that the returned choice by menu is numeric, not the option strings. So you should use case 1 rather than case 'opt1'.

A good practice for switch is to include otherwise block, like

switch q
    case 1
        % do opt1
    case 2
        % do opt2
    otherwise
        disp(q)
        error('Invalid option')
end

Then you will know it goes to otherwise block due to some error in your case.