我会说这是你正在绘制的大量积分导致经济放缓.一个选项是缩减采样..也可以使用较低级别的功能进行绘制(检查
this related post以获得plot3 / scatter3 / line性能的比较).
考虑以下针对速度优化的动画:
[X Y Z] = sphere(64);
X = X(:); Y = Y(:); Z = Z(:);
%# set-up figure
hFig = figure('Backingstore','off', 'renderer','zbuffer');
%# use lower-level function LINE
line(0.50*[X,X], 0.50*[Y,Y], 0.50*[Z,Z], 'LineStyle','none', 'Marker','.', 'MarkerSize',1, 'Color','r')
line(0.75*[X,X], 0.75*[Y,Y], 0.75*[Z,Z], 'LineStyle','none', 'Marker','.', 'MarkerSize',1, 'Color','g')
line(1.00*[X,X], 1.00*[Y,Y], 1.00*[Z,Z], 'LineStyle','none', 'Marker','.', 'MarkerSize',1, 'Color','b')
view(3)
%# freeze the aspect ratio to override stretch-to-fill behaviour
axis vis3d
%# fix the axes limits manually
%#set(gca, 'xlim',[-1 1], 'ylim',[-1 1], 'zlim',[-1 1])
axis manual
%# maybe even remove the tick labels
%set(gca, 'xticklabel',[], 'yticklabel',[], 'zticklabel',[])
%# animate (until figure is closed)
while ishandle(hFig); camorbit(0.9,-0.1); drawnow; end
编辑:
如果我理解正确,你要做的是录制一个截屏视频(使用第三方应用),同时手动旋转图形,但在你的情况下,这些手动旋转是“跳跃”.另一方面,在一个while循环中使用CAMORBIT / VIEW动画你的数字运行顺畅……
我提出了另一种解决方案:首先使用鼠标旋转图形,然后在每个步骤(方位角,仰角)上写下这些视图配置.然后,您可以在录制视频时使用VIEW功能重播它们,例如:
v = [...]; %# matrix where each row specify Az/El of view
for i=1:size(v,1)
view( v(i,:) )
drawnow
end
缺点是您必须以小步骤使用鼠标按下/旋转/释放(ROTATE3D对象不会暴露鼠标移动事件)
我写了一个简单的函数来帮助你完成这个过程.它加载保存的图形,启用3d旋转,并跟踪每一步的中间位置.完成后,按“完成”按钮返回视图列表…
function v = rotationDemo(figFileName)
views = []; %# list of views (Az,El)
hFig = hgload(figFileName); %# load the saved figure
views(1,:) = get(gca,'View'); %# store initial view
%# add a button, used to terminate the process
hButton = uicontrol('Style','pushbutton', 'Position',[400 1 80 20], ...
'String','Done?', 'Callback',@buttonCallback);
set(hFig, 'Toolbar','figure') %# restore toolbar
%# start 3d rotation, and handle post-callback to record intermediate views
h = rotate3d(hFig); %# get rotation object
set(h, 'ActionPostCallback',@rotateCallback)
set(h, 'Enable','on') %# enable rotation
msgbox('Rotate the view step-by-step', 'rotate3d', 'warn', 'modal')
uiwait(hFig) %# wait for user to click button
delete(hButton) %# delete button on finish
set(h, 'Enable','off') %# disable rotation
v = round(views); %# return the list of views
%# callback functions
function rotateCallback(o,e)
views(end+1,:) = get(e.Axes,'View'); %# add current view to list
end
function buttonCallback(o,e)
uiresume(gcbf) %# uiresume(hFig)
end
end
你可以调用上面的函数,然后重放动画:
v = rotationDemo('smooth_rotation.fig');
for i=1:size(v,1)
view(v(i,:))
drawnow
end
我们可以通过简单的插值来平滑过渡:
v = rotationDemo('smooth_rotation.fig');
n = size(v,1);
nn = linspace(1,n,100)'; %'# use 100 steps
vv = round( [interp1(v(:,1),nn) interp1(v(:,2),nn)] );
for i=1:size(vv,1)
view(vv(i,:))
DRAWNOW %# or PAUSE(..) to slow it down
end
作为旁注,我应该提到ROTATE3D和CAMORBIT有不同的效果. ROTATE3D更改当前轴的View属性,而CAMORBIT控制当前轴的CameraTarget / CameraPosition / CameraUpVector的相机属性.