【发布时间】:2014-08-11 23:20:23
【问题描述】:
我想在我现有的 Matlab 代码中添加一个列表框。我希望在绘制图形的代码的第二个选项卡上显示此列表框。我希望在当前文件夹中使用 .bmp 保存的绘图填充列表框。我对 MATLAB gui 几乎没有经验,甚至无法显示列表框。
这是我当前的代码
function PizanoGUI()
x=linspace(-2,2,100);
power=1;
y=x.^power;
ctrl_fh = figure;
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);
hButton = uicontrol('Style','pushbutton','Parent',ctrl_fh,...
'Position',[45 50 100 20],...
'String','EXIT','Callback',@close_Callback);
htext=uicontrol('Style', 'text',...
'String', 'Welcome! Please Enter any value p to view the graph of y=x^p then press enter', ...
'Position',[35,250,500,90], ...
'FontSize',20);
function close_Callback(hObject, eventdata, handles)
close all;
end
function reset(source,event,handles,varargin)
fprintf('resetting...\n');
power=1;
set(hPwr,'String',num2str(power));
y=x.^power;
close(gcf);
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'));
close(gcf);
compute_and_draw_plot();
end
function compute_and_draw_plot()
plot_fh = figure;
y=x.^power;
figure(plot_fh); plot(x,y)
xlabel('X axis')
ylabel('Y axis')
str = sprintf('Plot of Y=X^%d',power);
title(str);
hButton = uicontrol('Style','pushbutton','Parent',plot_fh,...
'Position',[80 395 100 20],...
'String','Previous','Callback',@pushbutton1_Callback);
function pushbutton1_Callback(source, eventdata, handles)
close(gcf);
PizanoGUI();
end
filename = inputdlg('Save figure as...');
extensions = {'fig','bmp'};
for k = 1:length(extensions)
saveas(gcf, filename{:}, extensions{k})
set(gcf,'PaperPositionMode','auto')
end
end
end
【问题讨论】:
标签: matlab user-interface listbox