我需要在MATLAB中为我的项目创建一个GUI。我到处寻找编写GUI的示例,但是没有找到很多。有哪些编写MATLAB GUI的好网站或技巧?
我需要在MATLAB中为我的项目创建一个GUI。我到处寻找编写GUI的示例,但是没有找到很多。有哪些编写MATLAB GUI的好网站或技巧?
function SampleGUI()
x=linspace(-2,2,100);
power=1;
y=x.^power;
ctrl_fh = figure; % controls figure handle
plot_fh = figure; % plot figure handle
plot(x,y);
% uicontrol handles:
hPwr = uicontrol('Style','edit','Parent',...
ctrl_fh,...
'Position',[45 100 100 20],...
'String',num2str(power),...
'CallBack',@pwrHandler);
hButton = uicontrol('Style','pushbutton','Parent',ctrl_fh,...
'Position',[45 150 100 20],...
'String','Reset','Callback',@reset);
function reset(source,event,handles,varargin) % boilerplate argument string
fprintf('resetting...\n');
power=1;
set(hPwr,'String',num2str(power));
y=x.^power;
compute_and_draw_plot();
end
function pwrHandler(source,event,handles,varargin)
power=str2num(get(hPwr,'string'));
fprintf('Setting power to %s\n',get(hPwr,'string'));
compute_and_draw_plot();
end
function compute_and_draw_plot()
y=x.^power;
figure(plot_fh); plot(x,y);
end
end