MATLAB課堂作業: Finale
依據範例一所示之內容,請使用uicontrol指令自行寫出功能相同之M檔案:
程式內容:
function unicontrol_demo
% SIMPLE_GUI Select a data set from the pop-up menu, then% click one of the
% plot-type push buttons. Clicking the button
% plots the selected data in the axes.
f = figure('Visible','off','Position',[360,500,450,285]);
hbutton = uicontrol('Style','pushbutton','String','執行','Position',[350,330,100,40],'Callback',{@popup_menu_Callback});
hpopup = uicontrol('Style','popupmenu','String','plot(x)pie(x)hist(y)ezplot3(f)polar(theta,r)area(x,y)','Position',[170,335,150,25]);
htext = uicontrol('Style','text','String','請輸入繪圖指令:','Position',[60,335,100,25]);
hfigure = axes('Units','pixels','Position',[50,60,400,250]);
set(f,'Name','unicontrol_demo')
movegui(f,'center')
set(f,'Visible','on')
plot(rand(5));
function popup_menu_Callback(source,eventdata)
val = get(hpopup,'Value');
switch val;
case 1 % User selects plot(x).
plot(rand(5))
case 2 % User selects pie(x).
n = round(10*rand)+10;
pie(2:4:n);
case 3 % User selects hist(y).
hist(randn(1000,1));
case 4 % User selects ezplot3(f).
ezplot3('t*sin(t)', 'cos(t)', 't', [0,6*pi])
case 5 % User selects polar(theta,r).
theta = linspace(0, 2*pi);
polar(theta, 3+2*rand*cos(4*theta));
case 6 % User selects area(x,y).
y=[1 1.2 1.5 2*rand;4 4.5 6.6 7*rand;5 6.5 8 15*rand]';
area([1980 1990 2000 2008],y);
grid on;colormap cool;
end
end
end
執行結果:
plot pie


historgram ezplot3


polar area


沒有留言:
張貼留言