Matlab 版 (精华区)
发信人: zjliu (秋天的萝卜), 信区: Matlab
标 题: [合集][转载]关税 /供大家学习
发信站: 哈工大紫丁香 (2003年06月12日21:33:22 星期四), 站内信件
────────────────────────────────────────
zjliu (秋天的萝卜) 于 figpos=[100 200 150 125];
h_fig=figure('Position',figpos);
for framenumber=1:20
subplot(121);
plot(sin(0:0.1:(2*framenumber*pi/20)),...
0:0.1:(2*framenumber*pi/20),'--r');
axis([-1 1 0 2*pi]);
subplot(122);
plot(0,exp(-(framenumber-1)/3),'*g');
axis([-1 1 0 1]);axis('off');
drawnow;
M(framenumber)=getframe(h_fig);
end
pause
delete(h_fig)
h_newfig=figure('Position',figpos)
axis off
movie(h_newfig,M, -5)
练习:
1 drawnow是作什么用的?
2 movie(h_newfig,M,-5) 中-5是什么意思?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 figure;
subplot(221);
plot(1:10);
subplot(222);
x=0:0.1:(2*pi);
plot(x,sin(x))
title('sin wave'); xlabel('x');ylabel('y');
subplot(223);
sphere(15);
subplot(224)
cylinder([1 .5 1]);
figure_position=get(gcf,'position');
rectangle_vector=[figure_position(3:4)/2 figure_position(3:4)/2];
subplot(222)
for loop=0:20
plot(x,sin(x+2*pi*loop/21));
title('sin wave');xlabel('x');ylabel('y');
M(:,loop+1)=getframe(gcf,rectangle_vector);
end
pause(3)
figure
movie(M);
pause(3)
figure('pos',rectangle_vector);
movie(gcf,M,5);
练习:
为何这里rectangle_vector这样设置?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 h_fig=figure;
subplot(2,1,1);
plot(abs((0-5)));axis([0 11 0 5])
subplot(212);
plot(sin(0:4*pi));axis([0 4*pi -1 1])
subplot(211)
figposition=get(h_fig,'position');
rectangle_vector=[0 figposition(4)/2 figposition(3) figposition(4)/2];
for framenumber=1:10;
plot(abs((0:(framenumber-1))-5)); axis([0 11 0 5]);
M(framenumber)=getframe(h_fig,rectangle_vector);
end
movie(h_fig,M,-3,12,rectangle_vector);
pause(2)
left=100;
bottom=150;
NewFigure=figure('position',[left bottom rectangle_vector(3:4)]);
movie(NewFigure,M,-3);
movie2avi(M,'1','fps',12,'videoname','avi1')
练习:
1 movie(h_fig,M,-3,12,rectangle_vector)中参数 是什么意思
2 movie2avi(M,'1','fps',12,'videoname','avi1') 是起什么作用
────────────────────────────────────────
zjliu (秋天的萝卜) 于 pause
t=0: 0.01:10*pi;
x=t.*sin(t);y=t.*cos(t);
comet3(x,y,t);
练习:
观察当0.01换成0.001时的行为?comet在讲什么故事?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 pause
t=0:0.01:10*pi;
x=t.*sin(t);y=t.*cos(t);
comet3(x,y,t);
pause(2)
figure
axislimits=[min(x) max(x) min(y) max(y) min(t) max(t)];
for indexnumber=1:length(x)
plot3(x(indexnumber),y(indexnumber),t(indexnumber),'bo');
axis(axislimits);
drawnow;
end
pause(2)
figure
axis(axislimits);
line_handle=line(x(1),y(1),t(1),...
'color','c',...
'linestyle','o');
for indexnumber=2:length(x)
delete(line_handle);
line_handle=line(x(indexnumber),...
y(indexnumber),...
t(indexnumber),...
'color','b',...
'linestyle','o');
drawnow;
end
pause(2)
figure
line_handle=line(x(1),y(1),t(1),...
'color','r',...
'linestyle','o');
set(line_handle,'erasemode','xor');
axis(axislimits);
for indexnumber=2:length(x)
for indexnumber=2:length(x)
set(line_handle,'xdata',x(indexnumber),...
'ydata',y(indexnumber),...
'zdata',t(indexnumber));
drawnow
end
练习
1 分析为何后面三个动画的速度会不一样,你是否遇到过同样的问题?
2 把 xor 换成 none, background, normal 分别是什么现象
如果用background模式,最后加上 refresh
────────────────────────────────────────
zjliu (秋天的萝卜) 于 %create the figure
figure('position',[150 100 200 150],...
'menubar','none',...
'color','white');
%create the uicontrol objects with normalized units
h_frame=uicontrol('style','frame',...
'units','normalized',...
'position',[0 0 1 1]);
h_popup_font=uicontrol('style','popup',...
'units','normalized',...
'position',[.3 .1 .65 .15],...
'string','Helvetica|Times|Courier|Symbol');
h_stext_font=uicontrol('style','text',...
'units','normalized',...
'position', [.05 .1 .25 .15],...
'string','Fonts:');
h_edit_multi=uicontrol('style','edit',...
'units','normalized',...
'position',[.05 .5 .9 .45],...
'string',['Line Number 1|Line #2|and line Number 3'],...
'max',2);
练习
1 试验一下上述代码,看一下放大缩小窗口带来的影响
2 想一下,为何上述参数,例如 [0.05 .5 .9 .45] 是小数,如果
变成整数,会有什么效果
────────────────────────────────────────
zjliu (秋天的萝卜) 于 [filename,pathname]=uigetfile('*.m',...
'小羊',...
100,100);
pause(3)
[filename1,pathname1]=uiputfile('ex1.m',...
'小古',...
100,100);
pause(3)
x=0:0.1:1
plot(x,x)
h=text(0.5,0.5,'小帆');
font=uisetfont(h)
color=uisetcolor(h)
练习
1 filename和pathname中是什么内容
2 font,和color是什么数据结构
────────────────────────────────────────
zjliu (秋天的萝卜) 于 h_wfig=warndlg('Warning Message String',...
'warning Dialog');
h_efig=errordlg('Not a valid input',...
'Input Error','on');
h_helpdlg=helpdlg('Try again!');
msgbox('My Error Message','Error Window Name','error');
msgbox('My Help Message','Help Window Name','help');
msgbox('My Warning Message','Warning Window Name','Warn');
%msgbox('My Message','Window Name','custom', iconData,iconCmap);
%string_returned=questdlg(QuestionString,ButtonString_1,ButtonString_2);
%string_returned=questdlg(QuestionString,ButtonString_1,ButtonString_2,Button
String_3,DefaultString);
question_ans=questdlg('Do you want a hard copy',...
'OUTPUT','Yes','N0','N0')
if strcmp(question_ans,'Yes')
print
end
answers=inputdlg({'My first question',...
'My 2nd question',...
'My 3rd question'},...
'Window Name',[1 2 1],...
{'defAns1','defAns2','defAns3'}); %
练习:
对msgbox 做一个你自己的图标
────────────────────────────────────────
zjliu (秋天的萝卜) 于 h_fig = figure('MenuBar','none');
axes('position',[.07 .5 .86 .4],'box','on')
h_frame_1 = uicontrol(h_fig,...
'Units','normalized','Position',[ 0 0 1 0.4 ],...
'Style','frame');
h_frame_2 = uicontrol(h_fig,...
'Units','normalized','Position',[0.08 0.05 0.84 0.11 ],...
'Style','frame');
box_clbk_str = ['boxstatus = get(h_box,''value'');'...
'if boxstatus == 0;'...
' set(gca,''box'',''off'');'...
'else;'...
' set(gca,''box'',''on'');'...
'end;'...
'boxstatus = get(gca,''box'');'...
'set(h_status,''string'',' ...
'[''The box property is '' boxstatus]);'];
h_box = uicontrol(h_fig,...
'CallBack',box_clbk_str,...
'Units','normalized',...
'Position',[ 0.7 0.2 0.16 0.07 ],...
'String','Box',...
'Style','checkbox',...
'Value',[ 1 ]);
grid_clbk_str = ['gridstatus = get(h_grid,''value'');'...
'if gridstatus == 0;'...
' grid off;'...
'else;'...
' grid on;'...
'end;'...
'gridstatus = get(gca,''xgrid'');'...
'set(h_status,''string'',' ...
'[''The grid is '' gridstatus]);'];
h_grid = uicontrol(h_fig,...
'CallBack',grid_clbk_str,...
'Units','normalized','Position',[ 0.7 0.3 0.16 0.07 ],...
'String','Grid',...
'Style','checkbox');
plot_clbk_str = [...
'err_ind = 0;'...
'eval([''x = '' get(h_xdata,''string'') '';''],'...
' ''err_ind=1;'');'...
'if err_ind == 0;'...
' eval([''y = '' get(h_ydata,''string'') '';''],'...
' ''err_ind=2;'');'...
'end;'...
'if err_ind == 0;'...
' plot(x,y);'...
' boxstatus = get(h_box,''value'');'...
' if boxstatus == 0;'...
' set(gca,''box'',''off'');'...
' else;'...
' set(gca,''box'',''on'');'...
' end;'...
' gridstatus = get(h_grid,''value'');'...
' if gridstatus == 0;'...
' grid off;'...
' else;'...
' grid on;'...
' end;'...
' set(h_status,''string'',''Function Plotted'');'...
'elseif err_ind == 1;'...
' set(h_status,''string'',''Error defining x'');'...
'elseif err_ind == 2;'...
' set(h_status,''string'',''Error defining y(x)'');'...
'end'];
h_ydata = uicontrol(h_fig,...
'CallBack',plot_clbk_str,...
'Units','normalized','Position',[ 0.25 0.2 0.39 0.07 ],...
'String','(x*.1).^2',...
'Style','edit');
h_xdata = uicontrol(h_fig,...
'CallBack',plot_clbk_str,...
'Units','normalized','Position',[ 0.25 0.3 0.39 0.07 ],...
'String','-10:10',...
'Style','edit');
h_status = uicontrol(h_fig,...
'Units','normalized','Position',[ 0.1 0.07 0.8 0.07 ],...
'String','Status Window',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized','Position',[ 0.08 0.3 0.15 0.07 ],...
'String','x =',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized','Position',[ 0.08 0.2 0.15 0.07 ],...
'String','y(x) =',...
'Style','text');
eval(plot_clbk_str);
练习:
1 搞清楚程序运行的逻辑,它是如何工作的
2 这样的回调函数设计有什么问题?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 function gui15(command_str)
if nargin == 0
command_str = 'initialize';
end
global h_box h_grid h_ydata h_xdata h_status
if strcmp(command_str,'initialize')
h_figs = get(0,'children');
fig_exists = 0;
for fig = h_figs'
fig_exists = strcmp(get(fig,'name'),...
'Function Plotter');
if fig_exists
figure(fig); % Bring figure to front of screen.
return; % No need to reinitialize, exit function.
end
end
h_fig = figure('name','Function Plotter');
axes('position',[.07 .5 .86 .4])
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0 0 1 0.4 ],...
'Style','frame');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[0.08 0.05 0.84 0.11 ],...
'Style','frame' );
h_box = uicontrol(h_fig,...
'CallBack','gui15(''Set Box'');',...
'Units','normalized',...
'Position',[ 0.7 0.2 0.16 0.07 ],...
'String','Box',...
'Style','checkbox',...
'Value',[ 1 ]);
h_grid = uicontrol(h_fig,...
'CallBack','gui15(''Set Grid'');',...
'Units','normalized',...
'Position',[ 0.7 0.3 0.16 0.07 ],...
'String','Grid',...
'Style','checkbox');
h_ydata = uicontrol(h_fig,...
'CallBack','gui15(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.2 0.39 0.07 ],...
'String','(x*.1).^2',...
'Style','edit');
h_xdata = uicontrol(h_fig,...
'CallBack','gui15(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.3 0.39 0.07 ],...
'String','-10:10',...
'Style','edit');
h_status = uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.1 0.07 0.8 0.07 ],...
'String','Status Window',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.08 0.3 0.15 0.07 ],...
'String','x =',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.08 0.2 0.15 0.07 ],...
'String','y(x) =',...
'Style','text');
gui15('Plot Function');
elseif strcmp(command_str,'Set Box')
boxstatus = get(h_box,'value');
if boxstatus == 0;
set(gca,'box','off');
else
set(gca,'box','on');
end
set(h_status,'string',...
['The box property is ' get(gca,'box')]);
elseif strcmp(command_str,'Set Grid')
gridstatus = get(h_grid,'value');
if gridstatus == 0
grid off
else;
grid on
end
set(h_status,'string',...
['The grid is ' get(gca,'xgrid')]);
elseif strcmp(command_str,'Plot Function')
err_ind = 0;
eval(['x = ' get(h_xdata,'string') ';'],'err_ind=1;');
if err_ind == 0;
eval(['y = ' get(h_ydata,'string') ';'],'err_ind=2;');
end
if err_ind == 0
plot(x,y);
gui15('Set Box');
gui15('Set Grid');
set(h_status,'string','Function Plotted');
elseif err_ind == 1
set(h_status,'string','Error defining x');
elseif err_ind == 2
set(h_status,'string','Error defining y(x)');
end
end
练习:
1 分析这个关税程序与前一程序有何不同?
2 想一想这个程序可能会有什么问题?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 function gui16(command_str)
if nargin == 0
command_str = 'initialize';
end
if ~strcmp(command_str,'initialize')
handles=get(gcf,'userdata');
h_box=handles(1);
h_grid=handles(2);
h_ydata=handles(3);
h_xdata=handles(4);
h_status=handles(5);
end
if strcmp(command_str,'initialize')
h_figs = get(0,'children');
fig_exists = 0;
for fig = h_figs'
fig_exists = strcmp(get(fig,'name'),...
'Function Plotter');
if fig_exists
figure(fig);
return;
end
end
h_fig = figure('name','Function Plotter');
axes('position',[.07 .5 .86 .4])
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0 0 1 0.4 ],...
'Style','frame');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[0.08 0.05 0.84 0.11 ],...
'Style','frame' );
h_box = uicontrol(h_fig,...
'CallBack','gui16(''Set Box'');',...
'Units','normalized',...
'Position',[ 0.7 0.2 0.16 0.07 ],...
'String','Box',...
'Style','checkbox',...
'Value',[ 1 ]);
h_grid = uicontrol(h_fig,...
'CallBack','gui16(''Set Grid'');',...
'Units','normalized',...
'Position',[ 0.7 0.3 0.16 0.07 ],...
'String','Grid',...
'Style','checkbox');
% Create the edit boxes for the x data.
h_ydata = uicontrol(h_fig,...
'CallBack','gui16(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.2 0.39 0.07 ],...
'String','(x*.1).^2',...
'Style','edit');
h_xdata = uicontrol(h_fig,...
'CallBack','gui16(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.3 0.39 0.07 ],...
'String','-10:10',...
'Style','edit');
h_status = uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.1 0.07 0.8 0.07 ],...
'String','Status Window',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.08 0.3 0.15 0.07 ],...
'String','x =',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.08 0.2 0.15 0.07 ],...
'String','y(x) =',...
'Style','text');
handles = [h_box h_grid h_ydata h_xdata h_status];
set(h_fig,'userdata',handles);
gui16('Plot Function');
elseif strcmp(command_str,'Set Box')
boxstatus = get(h_box,'value');
if boxstatus == 0;
set(gca,'box','off');
else
set(gca,'box','on');
end
set(h_status,'string',...
['The box property is ' get(gca,'box')]);
elseif strcmp(command_str,'Set Grid')
gridstatus = get(h_grid,'value');
if gridstatus == 0
grid off
else;
grid on
end
set(h_status,'string',...
['The grid is ' get(gca,'xgrid')]);
elseif strcmp(command_str,'Plot Function')
err_ind = 0;
eval(['x = ' get(h_xdata,'string') ';'],'err_ind=1;');
if err_ind == 0;
eval(['y = ' get(h_ydata,'string') ';'],'err_ind=2;');
end
if err_ind == 0
plot(x,y);
gui16('Set Box');
gui16('Set Grid');
set(h_status,'string','Function Plotted');
elseif err_ind == 1
set(h_status,'string','Error defining x');
elseif err_ind == 2
set(h_status,'string','Error defining y(x)');
end
end
练习:
1 分析这个关税程序与灌水15有何不同?
2 为何这个程序更安全一些?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 function gui17(command_str)
if nargin == 0
command_str = 'initialize';
end
if ~strcmp(command_str,'initialize')
h_fig=gcf;
if ~strcmp(get(h_fig,'tag'),'snowdy')
h_figs = get(0,'children');
h_fig=findobj(h_figs,'flat','tag','snowdy');
if(length(h_fig)==0)
gui17('initialize');
return;
end
end
h_box=findobj(h_fig(1),'tag','h_box');
h_grid=findobj(h_fig(1),'tag','h_grid');
h_ydata=findobj(h_fig(1),'tag','h_ydata');
h_xdata=findobj(h_fig(1),'tag','h_xdata');
h_status=findobj(h_fig(1),'tag','h_status');
end
if strcmp(command_str,'initialize')
h_figs = get(0,'children');
h_fig=findobj(h_figs,'flat','tag','snowdy');
if length(h_fig)>0
figure(h_fig(1));
return
end
h_fig=figure('name','Function plotter','tag','snowdy');
fig_exists = 0;
for fig = h_figs'
fig_exists = strcmp(get(fig,'name'),...
'Function Plotter');
if fig_exists
figure(fig);
return;
end
end
axes('position',[.07 .5 .86 .4])
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0 0 1 0.4 ],...
'Style','frame');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[0.08 0.05 0.84 0.11 ],...
'Style','frame' );
h_box = uicontrol(h_fig,...
'CallBack','gui17(''Set Box'');',...
'Units','normalized',...
'Position',[ 0.7 0.2 0.16 0.07 ],...
'String','Box',...
'Style','checkbox',...
'Value',[ 1 ],...
'tag','h_box');
h_grid = uicontrol(h_fig,...
'CallBack','gui17(''Set Grid'');',...
'Units','normalized',...
'Position',[ 0.7 0.3 0.16 0.07 ],...
'String','Grid',...
'Style','checkbox',...
'tag','h_grid');
h_ydata = uicontrol(h_fig,...
'CallBack','gui17(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.2 0.39 0.07 ],...
'String','(x*.1).^2',...
'Style','edit',...
'tag','h_ydata');
h_xdata = uicontrol(h_fig,...
'CallBack','gui17(''Plot Function'');',...
'Units','normalized',...
'Position',[ 0.25 0.3 0.39 0.07 ],...
'String','-10:10',...
'Style','edit',...
'tag','h_xdata');
h_status = uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.1 0.07 0.8 0.07 ],...
'String','Status Window',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.08 0.3 0.15 0.07 ],...
'String','x =',...
'Style','text');
uicontrol(h_fig,...
'Units','normalized',...
'Position',[ 0.08 0.2 0.15 0.07 ],...
'String','y(x) =',...
'Style','text');
gui17('Plot Function');
elseif strcmp(command_str,'Set Box')
boxstatus = get(h_box,'value');
if boxstatus == 0;
set(gca,'box','off');
else
set(gca,'box','on');
end
set(h_status,'string',...
['The box property is ' get(gca,'box')]);
elseif strcmp(command_str,'Set Grid')
gridstatus = get(h_grid,'value');
if gridstatus == 0
grid off
else;
grid on
end
set(h_status,'string',...
['The grid is ' get(gca,'xgrid')]);
elseif strcmp(command_str,'Plot Function')
err_ind = 0;
eval(['x = ' get(h_xdata,'string') ';'],'err_ind=1;');
if err_ind == 0;
eval(['y = ' get(h_ydata,'string') ';'],'err_ind=2;');
end
if err_ind == 0
plot(x,y);
gui17('Set Box');
gui17('Set Grid');
set(h_status,'string','Function Plotted');
elseif err_ind == 1
set(h_status,'string','Error defining x');
elseif err_ind == 2
set(h_status,'string','Error defining y(x)');
end
end
练习:
1 这里 findobj起什么作用?
2 这里 snowdy标志什么?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 pause
x=[0 1 1 0 0 0 1 1 0 0 NaN 1 1 NaN 1 1 NaN 0 0];
y=[0 0 1 1 0 0 0 1 1 0 NaN 0 0 NaN 1 1 NaN 1 1];
z=[0 0 0 0 0 1 1 1 1 1 NaN 1 0 NaN 0 1 NaN 1 0];
cube_h=plot3(x-0.5,y-0.5,z-0.5);
axis('square');
axis([-1 1 -1 1 -1 1]*2);
view(-37.5,15);
set(cube_h,'erasemode','background');
rotation_increment=1;
rotation_axis=[0 0 1];
rotation_origin=[0 0 0];
num_of_incr=360/rotation_increment;
for loop=1:num_of_incr
rotate(cube_h,rotation_axis,...
rotation_increment,rotation_origin);
drawnow;
end
练习:
1 x,y,z中的 Nan是起到什么作用?
2 立方体为何会旋转?如何旋转的?
3 view 起什么作用?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 function x=rotcube()
x=[0 1 1 0 0 0 1 1 0 0 NaN 1 1 NaN 1 1 NaN 0 0];
y=[0 0 1 1 0 0 0 1 1 0 NaN 0 0 NaN 1 1 NaN 1 1];
z=[0 0 0 0 0 1 1 1 1 1 NaN 1 0 NaN 0 1 NaN 1 0];
rot_axis=[0 0 1];
rot_org=[0 0 0];
cube_h=plot3(x-0.5,y-0.5,z-0.5);
axis('square');
axis([-1 1 -1 1 -1 1]*2);
view(-37,30);
set(cube_h,'erasemode','background');
rotation_increment=5;
rotation_axis=rot_axis;
rotation_origin=rot_org;
fig_h=gcf;
key='j';
while key~=27
if waitforbuttonpress==1;
key=get(fig_h,'currentcharacter');
switch key
case 28
% case 'j'
rotation_axis=[0 0 1];
rotation_increment=-5;
case 29
%case 'k'
rotation_axis=[0 0 1];
rotation_increment=5;
case 30
%case 'l'
rotation_axis=[0 1 0];
rotation_increment=5;
case 31
% case 'i'
rotation_axis=[0 1 0];
rotation_increment=-5;
case 27
close(fig_h)
clear
return
end
rotate(cube_h,rotation_axis,...
rotation_increment,rotation_origin);
drawnow;
end
end
x=key
练习
1 如果你用的是笔记本,比如 snowdy之流:),请修改程序,我就不多说了
2 学习waitforbuttonpress的用法
3 学习 get(fig_h,'currentcharacter')的用法
4 玩一下这个程序,看看有没有动起来
────────────────────────────────────────
zjliu (秋天的萝卜) 于 function x=rotcube2()
x=[0 1 1 0 0 0 1 1 0 0 NaN 1 1 NaN 1 1 NaN 0 0];
y=[0 0 1 1 0 0 0 1 1 0 NaN 0 0 NaN 1 1 NaN 1 1];
z=[0 0 0 0 0 1 1 1 1 1 NaN 1 0 NaN 0 1 NaN 1 0];
cube_h=plot3(x-0.5,y-0.5,z-0.5);
axis('square');
axis([-1 1 -1 1 -1 1]*2);
view(-37.5,15);
set(cube_h,'erasemode','background');
rotation_increment=5;
rotation_axis=[0 0 1];
rotation_origin=[0 0 0];
num_of_incr=360/rotation_increment;
pause(2)
for loop=1:num_of_incr
rotate(cube_h,rotation_axis,...
rotation_increment,rotation_origin);
drawnow;
end
refresh
pause(2)
cube2_h=line(x+1,y+1,z+1,'erasemode','background');
for loop=1:num_of_incr
rotate(cube2_h,rotation_axis+[1 1 0],...
rotation_increment,rotation_origin+1);
drawnow;
end
refresh
pause(2)
x=[0 0 1 1 0];y=[0 1 1 0 0];z=zeros(size(x));
rotation_axis=[0 0 1];
rotation_origin=[0 0 0];
num_of_incr=360/rotation_increment;
s1_h=surf([x;x]-.5,[y;y]-.5,[z+0.5;z-0.5]);
set(s1_h,'erasemode','background',...
'facecolor','none',...
'edgecolor','g');
s2_h=surface([x;x]+1.5,[y;y]+1.5,[z+.5;z-0.5]+1.5,...
'erasemode','background',...
'facecolor','g',...
'edgecolor','r');
s3_h=surface([x;x]+1.5,[y;y]+1.5,[z+.5;z-0.5],...
'erasemode','background',...
'facecolor','r',...
'edgecolor','b');
axis([-3 3 -3 3 -3 3]);axis('square');
for loop=1:num_of_incr
rotate(s1_h,rotation_axis,...
rotation_increment,rotation_origin);
rotate(s2_h,rotation_axis+[1 1 0],...
rotation_increment,rotation_origin+1);
rotate(s3_h,rotation_axis,...
rotation_increment,rotation_origin);
drawnow
end
refresh
练习:
1 facecolor 是起什么作用的?
────────────────────────────────────────
zjliu (秋天的萝卜) 于 x=0:50;
y=sin(.05*x+cos(x*.1));
figure_handle=figure('backingstore','off');
axes('drawmode','fast','box','on');
axis([min(x) max(x) min(y) max(y)]);
line_handle=line(x(1:2),y(1:2));
set(line_handle,'linewidth',2,'erasemode','none');
for index_counter=2:length(x);
set(line_handle,...
'xdata',[x(index_counter+[0 -1])],...
'ydata',[y(index_counter+[0 -1])]);
pause(.5)
drawnow
end
line(x,y,'linewidth',2);
refresh
[imagematrix,map]=getframe(figure_handle);
newfig=figure;
figpos=get(newfig,'position');
set(newfig,'position',...
[figpos(1:2) fliplr(size(imagematrix))]);
axes('units','normalized','position',[0 0 1 1]);
image(imagematrix);
colormap(map);
set(gca,'visible','off');
练习:
99不忘,依18舍
────────────────────────────────────────
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:412.242毫秒