带动画的实时脚本
Live Script with animation
MATLAB 2016a 引入了 Live Scripts,允许在脚本旁边显示绘图输出。是否可以以某种方式显示动画?例如,以下正则代码将绘制几个点,然后旋转 axes
:
x = rand(10, 3);
plot3(x(:, 1), x(:, 2), x(:, 3), 'o')
for ii = 1:360
camorbit(1, 10*cos(ii/90*pi)*pi/45)
drawnow
pause(0.01)
end
如果将其嵌入到实时脚本中,则会显示初始情节,然后在循环 运行 时似乎什么也没有发生,然后会显示最后一个方面(与原始情节相同)在一个新的显示项目中。
或者,是否可以选择与实时脚本中的绘图进行交互(除了双击以在新图中打开绘图)?例如。 rotate3d
没有影响。
编辑: 从 2019a 版开始,可以根据 release notes.
制作动画
看来答案是否定的 - Live Scripts 还太年轻,功能还不够丰富。仅凭它们不可调试的事实,我就会远离它们 1-2 个版本。
你调查过 Matlab Notebooks 了吗?如果您追求漂亮的格式和一些基本的交互性,这可能就是您要找的。
2016b 版添加了操作 axes
的选项,当鼠标悬停在 axes
上时会出现控件。请注意,这不适用于不可见的 axes
(Visible='off'
)。相反,必须隐藏标尺和背景:
ax = axes;
x = rand(9, 3);
plot3(ax,x(:, 1), x(:, 2), x(:, 3), 'x');
% Hide rulers and background color
ax.Color = [1 1 1 0];
ax.XAxis.Visible ='off';
ax.YAxis.Visible ='off';
ax.ZAxis.Visible ='off';
用subplot
排列的轴也可以单独操作。
问题中发布的示例代码生成了截至 MATLAB 2019a 的旋转图。它在 2018b 中还不起作用。 2019a 的 release notes 提到
You can enable for-loop animations in the Live Editor to show changes
in plotted data over time. To enable animations in the Live Editor,
set the matlab.editor.AllowFigureAnimations
setting to true
:
s = settings;
s.matlab.editor.AllowFigureAnimation.PersonalValue = true;
运行 示例脚本前的这两行将产生预期的行为。
MATLAB 2016a 引入了 Live Scripts,允许在脚本旁边显示绘图输出。是否可以以某种方式显示动画?例如,以下正则代码将绘制几个点,然后旋转 axes
:
x = rand(10, 3);
plot3(x(:, 1), x(:, 2), x(:, 3), 'o')
for ii = 1:360
camorbit(1, 10*cos(ii/90*pi)*pi/45)
drawnow
pause(0.01)
end
如果将其嵌入到实时脚本中,则会显示初始情节,然后在循环 运行 时似乎什么也没有发生,然后会显示最后一个方面(与原始情节相同)在一个新的显示项目中。
或者,是否可以选择与实时脚本中的绘图进行交互(除了双击以在新图中打开绘图)?例如。 rotate3d
没有影响。
编辑: 从 2019a 版开始,可以根据 release notes.
制作动画看来答案是否定的 - Live Scripts 还太年轻,功能还不够丰富。仅凭它们不可调试的事实,我就会远离它们 1-2 个版本。 你调查过 Matlab Notebooks 了吗?如果您追求漂亮的格式和一些基本的交互性,这可能就是您要找的。
2016b 版添加了操作 axes
的选项,当鼠标悬停在 axes
上时会出现控件。请注意,这不适用于不可见的 axes
(Visible='off'
)。相反,必须隐藏标尺和背景:
ax = axes;
x = rand(9, 3);
plot3(ax,x(:, 1), x(:, 2), x(:, 3), 'x');
% Hide rulers and background color
ax.Color = [1 1 1 0];
ax.XAxis.Visible ='off';
ax.YAxis.Visible ='off';
ax.ZAxis.Visible ='off';
用subplot
排列的轴也可以单独操作。
问题中发布的示例代码生成了截至 MATLAB 2019a 的旋转图。它在 2018b 中还不起作用。 2019a 的 release notes 提到
You can enable for-loop animations in the Live Editor to show changes in plotted data over time. To enable animations in the Live Editor, set the
matlab.editor.AllowFigureAnimations
setting totrue
:s = settings; s.matlab.editor.AllowFigureAnimation.PersonalValue = true;
运行 示例脚本前的这两行将产生预期的行为。