views:

239

answers:

2

i have two set of button groups. first button groups has two radio buttons and second group has four radio buttons. if button 1 is selected in group1 and any one from the group 2. similarly for button2 in group 1 and any one from group2, respective function calls must be made on click of push button with these combinations. how to do it. there will be 8 separate function calls for their respective combinations. how to do the combination of button groups. switch case or if else statement did not work out?? kindly help.

A: 

Here is an idea.

First you create 2x4 cell array of your functions.

fnc_array = {fcn11, fcn12, fcn13, fcn14; fcn21, fcn22, fcn23, fcn24};

Then do switch case for each radio button in a group and return an index (say fcn_index1 for 1st group, and fcn_index2 for the 2nd group), which button selected.

Then you can call a function from your array with those indexes:

fcn_array{fcn_index1,fcn_index2}(arguments)
yuk
A: 

Switch and if..else should certainly work out, but you need to nest them, i.e. there's no way to switch on a pair of values.

switch valA
    case 1
        if isB
            out = fcn11(args{:});
        else
            out = fcn12(args{:});
        end
    case 2
        if isB
            out = fcn21(args{:});
        else
            out = fcn22(args{:});
        end
    case 3
        if isB
            out = fcn31(args{:});
        else
            out = fcn32(args{:});
        end
    case 4
        if isB
            out = fcn41(args{:});
        else
            out = fcn42(args{:});
        end
end
Nzbuu