mar*_*sei 14
与播放ActionPostCallback和ActionPreCallback肯定是一个解决方案,但可能不是最有效的一个.可以使用linkprop功能来同步相机位置属性.
linkprop([h(1) h(2)], 'CameraPosition'); %h is the axes handle
Run Code Online (Sandbox Code Playgroud)
linkprop可以同步两个或更多axes(2D或3D)的任何图形属性.它可以被视为linkaxes适用于2D图的功能的扩展,axes仅用于同步限制.在这里,我们可以使用linkprop同步摄像机位置属性,CameraPosition一个旋转时修改的属性axes.
这是一些代码
% DATA
[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z1 = sin(R)./R;
Z2 = sin(R);
% FIGURE
figure;
hax(1) = subplot(1,2,1); %give the first axes a handle
surf(Z1);
hax(2) = subplot(1,2,2); %give the second axes a handle
surf(Z2)
% synchronize the camera position
linkprop(hax, 'CameraPosition');
Run Code Online (Sandbox Code Playgroud)
您可以拥有一个图形属性列表
graph_props = fieldnames(get(gca));
Run Code Online (Sandbox Code Playgroud)
一种方法是在旋转事件上注册回调并在两个轴上同步新状态.
function syncPlots(A, B)
% A and B are two matrices that will be passed to surf()
s1 = subplot(1, 2, 1);
surf(A);
r1 = rotate3d;
s2 = subplot(1, 2, 2);
surf(B);
r2 = rotate3d;
function sync_callback(~, evd)
% Get view property of the plot that changed
newView = get(evd.Axes,'View');
% Synchronize View property of both plots
set(s1, 'View', newView);
set(s2, 'View', newView);
end
% Register Callbacks
set(r1,'ActionPostCallback',@sync_callback);
set(r1,'ActionPreCallback',@sync_callback);
set(r2,'ActionPostCallback',@sync_callback);
set(r2,'ActionPreCallback',@sync_callback);
end
Run Code Online (Sandbox Code Playgroud)