naxchange
naxchange

Reputation: 913

Matlab: Using values from multiple uicontrols to plot a graph

I am trying to combine values from several UI controls in order to select a particular graph output. Here's the code:

First we open the figure:

figure('position',[100 100 700 350]);

Part 1: The Popup UI control input value:

pullDown = uicontrol('style','popup',...
            'position',[10 680 180 10],...
            'string','Displacement|Velocity|Acceleration',...
            'callback',@function1); 

Part 2: The radiobutton UI control:

radioButtonGroup = uibuttongroup('visible','off',...
            'units','pixels','position',[0 0 1 2],'backgroundcolor','white');
        radio1 = uicontrol('Style','radiobutton','String','Computed',...
            'position',[250 20 100 30],'parent',radioButtonGroup);
        radio2 = uicontrol('Style','radiobutton','String','Recorded',...
            'position',[400 20 100 30],'parent',radioButtonGroup);

So, what I'm trying to do is maybe write an if-elseif that could help me do something like this (I'm just going to write in pseudocode):

if pullDown == 'Displacement' AND radio == 'Computed'
   plot(graph1,x);
else if pullDown == 'Displacement' AND radio = 'Recorded'
   plot(graph2,x);
...

and so on. Any ideas?

Thanks in advance!

NAX

Upvotes: 1

Views: 873

Answers (1)

bas
bas

Reputation: 209

You gotta do something along these lines:

For the radiobutton group, use a 'SelectionChangeFcn' .You can use the selection on the radiobutton to choose the plot you want to display(here is how: at the end of radioButtonGroup definition, add 'SelectionChangeFcn',@plotComputedOrRecorded):

function plotComputedOrRecorded(source,eventdata)
    switch get(eventdata.NewValue,'String')
        quantity = QuantityStrs{get(pullDown,'value')};
             %QuantityStrs = {'Displacement','Velocity','Acceleration'}
        case 'Computed'
            plotComputed(quantity);
        case 'Recorded'
            plotRecorded(quantity);
    end
end

You can then use two functions @plotComputed and @plotRecorded to plot the relevant quantities in the appropriate axis.

Upvotes: 1

Related Questions