[英]Matlab: Using values from multiple uicontrols to plot a graph
我試圖合並來自多個UI控件的值,以選擇特定的圖形輸出。 這是代碼:
首先我們打開圖:
figure('position',[100 100 700 350]);
第1部分:Popup UI控件輸入值:
pullDown = uicontrol('style','popup',...
'position',[10 680 180 10],...
'string','Displacement|Velocity|Acceleration',...
'callback',@function1);
第2部分:單選按鈕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);
...
等等。 有任何想法嗎?
提前致謝!
納克斯
您必須按照以下步驟進行操作:
對於單選按鈕組,請使用“ SelectionChangeFcn”。您可以使用單選按鈕上的選擇來選擇要顯示的圖(這是方法 :在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在相應的軸上繪制相關數量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.