0
我想什么@Amro建议我,我改变了代码的一部分,我得到了一些错误:/matlab的GUI单选按钮
请帮助我。
我设置的选项是:
options = {
{'r','g','b','c','m','y','k'} ;
{'x','o','.','s'} ;
{'1','2','3'} ;
{'2','3'} ;
{'1','3'} ;
{'1','2'}
};
现在,我在MATLAB中写道:
mainGUI(options)
,我得到了这些错误:
这是代码:
function mainGUI(options)
%# current options
opts = {'r', '.', '1'};
%# create main figure, with plot and options button
hFig = figure;
callback
%# options button callback function
function callback(o,e)
%# save current options (sharing data between the two GUIs)
setappdata(hFig, 'opts',opts);
%# display options dialog and wait for it
hOptsGUI = secondaryGUI(hFig, options);
waitfor(hOptsGUI);
%# get new options, and update plot accordingly
opts = getappdata(hFig, 'opts');
opts
end
end
function hFig = secondaryGUI(hParentFig, options)
%# create figure
hFig = figure('Menubar','none', 'Resize','off', ...
'WindowStyle','modal', 'Position',[100 100 350 200]);
movegui(hFig, 'center');
%# all possible plot options
options = cellfun(@(c) c(end:-1:1), options, 'Uniform',false);
num = length(options);
%# get saved settings
selected = getappdata(hParentFig, 'opts');
%# top/bottom panels
hPanBot = uipanel('Parent',hFig, 'BorderType','none', ...
'Units','normalized', 'Position',[0 0.0 1 0.2]);
hPanTop = uipanel('Parent',hFig, 'BorderType','none', ...
'Units','normalized', 'Position',[0 0.2 1 0.8]);
%# buttongroups in top panel
hBtnGrp = zeros(1,num);
width = 1/num;
for i=1:num
%# create button group
hBtnGrp(i) = uibuttongroup('Parent',hPanTop, ...
'Units','normalized', 'Position',[(i-1)*width 0 width 1]);
%# populate it with radio buttons
height = 1./numel(options{i});
for j=1:numel(options{i})
h = uicontrol('Parent',hBtnGrp(i), 'Style','Radio', ...
'Units','normalized', 'Position',[0.05 (j-1)*height 0.9 height], ...
'String',options{i}{j});
%# set initially selected values
if strcmp(selected{i},options{i}{j})
set(hBtnGrp(i), 'SelectedObject',h)
end
end
end
%# save button in bottom panel
uicontrol('Parent',hPanBot, 'Style','pushbutton', ...
'Units','normalized', 'Position',[0.3 0.2 0.4 0.6], ...
'String','start', 'Callback',@callback)
%# save button callback function
function callback(o,e)
%# get selected values
hObjs = get(hBtnGrp(:), 'SelectedObject');
vals = get(cell2mat(hObjs),{'String'});
%# update settings
setappdata(hParentFig, 'opts',vals);
%# close options dialog
close(hFig)
end
end
也许变量'opts'存在问题,因为没有以下值:{'r','。','1'}?
,因为我不知道为什么它超过矩阵尺寸,选项的长度为6
谢谢!
Hi和非常感谢你的评论,但它不是我所需要的正是:/我想再问一下,这样你就可以再次阅读我的问题吗? http://stackoverflow.com/questions/10775243/matlab-gui-buttons –
@AlonShmiel:另一个问题几乎是相同的,我仍然没有得到你想要做的事情(总是[问](http: )具体问题)...我试图解决你提到的所有问题。因此,如果没有别的,研究上面的代码,也许你会得到解决方案的想法。我一定要评论每一步,因此应该很容易遵循。 – Amro
嗨,我试过你建议我的。我只需要'图2'窗口,所以我删除'图1'窗口。我改变了我的新问题。如果可以的话,请帮助我。非常感谢你,阿隆。 –