我有一個uibuttongroup,裏面定義了單選按鈕。我有用相應的屬性定義的uipanels。我想要做的是能夠點擊一個單選按鈕,並且出現一個單選按鈕,然後單擊我的另一個單選按鈕以顯示另一個單選按鈕。這裏是我的代碼片段:當我按下單選按鈕時,可以看到一個值可見的面板
operation_type_1 = uibuttongroup(S.Test, 'Title', 'Operation Type', 'position', [0 0.3 panel_w/2 0.15]);
uicontrol('Parent',operation_type_1, 'Style', 'radiobutton',...
'String', 'invisible',...
'position', [0 0 0 0], 'Tag', 'invisibutton');
uicontrol('Parent',operation_type_1,'Style','radiobutton',...
'String', 'Time Operation',...
'Position', 100*[0.1 flooring(3.5, 'tp') 1.2 0.15], 'Tag', 'timeop1');
uicontrol('Parent',operation_type_1,'Style','radiobutton',...
'String', 'Volume Operation',...
'Position', 100*[0.1 flooring(2.5, 'tp') 1.2 0.15], 'Tag', 'volumeop1');
這定義了我的按鈕組和兩個單選按鈕。
然後,我有它創建了一個體積面板代碼:
除了作爲一個時間面板:
這些都是在相同的位置。我想要的是能夠點擊「Time Operation」單選按鈕並使時間面板可見,並且當我單擊「Volume Operation」單選按鈕時,可以看到音量面板。
我試過做switch case語句。我沒有得到錯誤,但我也沒有得到結果。例如,我的時間和音量面板的情況說明如下:
switch str
case 'timeop1'
if U.Value; S.result_panel_time1.Visible = 'On';
else S.result_panel_time1.Visible = 'Off';
end
case 'volumeop1'
if U.Value; S.result_panel_volume1.Visible = 'On';
else S.result_panel_volume1.Visible = 'Off';
end
如何獲得此功能?我沒有使用GUIDE,只是編寫一個MATLAB GUI。
UPDATE
我已經試過落實回調以下建議,但我得到一個「函數定義是錯誤的或不恰當嵌套。」錯誤。我用下面的功能:
function button_callback(U, varargin{2})
switch get(get(operation_type_1, 'SelectedObject'), 'Tag')
case 'timeop1'
if U.Value; S.result_panel_time1.Visible = 'On';
else S.result_panel_time1.Visible = 'Off';
end
case 'volumeop1'
if U.Value; S.result_panel_volume1.Visible = 'On';
else S.result_panel_volume1.Visible = 'Off';
end
end
end
而且我已經添加了回調 「...... '回調',{@pb_call,S}」 我timeop1和volumeop1。 (因爲我擁有的所有其他功能都在名爲pb_call.m的.m文件中)。該函數似乎嵌套很好,但錯誤指向確切的一個。
我已經更新了我與我是如何實現你的建議的問題。你能提出一個解決方案嗎?如果這解決了它,我會很樂意接受你的答案。 – Morgan