2012-10-08 45 views
1

我想結合幾個UI控件的值來選擇特定的圖形輸出。下面的代碼:Matlab:使用來自多個uicontrols的值繪製圖形

首先我們打開人物:

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

第1部分:彈出式UI控制輸入值:

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

第二部分:單選按鈕UI控件:

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); 

所以,我想要做的,也許寫一個if-elseif,可以幫助我做這樣的事情(我只是想寫入僞代碼):

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

等等。有任何想法嗎?

在此先感謝!

NAX

回答

1

你要做的東西沿着這些路線:

對於單選按鈕組,使用「SelectionChangeFcn」。你可以使用選擇的單選按鈕來選擇要顯示的情節(在這裏是how:在RadioButtonGroup中定義的末尾,添加「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 

然後你可以使用兩種功能@plotComputed和@plotRecorded繪製相應的數量在適當的軸。

+0

非常感謝你,那正是我需要的! – naxchange