Matlab:在特定图形上绘制线条
Matlab: Plot line on a particular figure
有没有办法指定在特定图形上绘制一条线。
我是 运行 一个代码,它在不同的点上绘制了多个图形。如果我在代码为 运行 时不与 matlab 交互,一切都可以正常工作。
问题是,我在 matlab 图形之间切换(手动检查结果),而 matlab 是 运行,这有时会导致 matlab 在错误的图形上绘制内容。
我在绘图之前打电话给 "figure(fig_handle)",但 matlab 有时仍然会在错误的图形上画东西。有人有解决方案吗?
没有specifying a specific axes object or handle, Matlab outputs the graphics to the current axes, which can be affected by user interaction:
User interaction can change the current axes. If you need to access a specific axes, store the axes handle in your program code when you create the axes and use this handle instead of gca
.
所以,在这种情况下,我建议这样:
figure(1);
x = linspace(0,2*pi);
plot(x,sin(x));
ax1 = gca;
ax1.NextPlot = 'add';
figure(2);
plot(ax1,x,cos(x));
无论图形顺序或用户引起的焦点如何,这都会将绘图添加到指定的轴。
有没有办法指定在特定图形上绘制一条线。 我是 运行 一个代码,它在不同的点上绘制了多个图形。如果我在代码为 运行 时不与 matlab 交互,一切都可以正常工作。
问题是,我在 matlab 图形之间切换(手动检查结果),而 matlab 是 运行,这有时会导致 matlab 在错误的图形上绘制内容。 我在绘图之前打电话给 "figure(fig_handle)",但 matlab 有时仍然会在错误的图形上画东西。有人有解决方案吗?
没有specifying a specific axes object or handle, Matlab outputs the graphics to the current axes, which can be affected by user interaction:
User interaction can change the current axes. If you need to access a specific axes, store the axes handle in your program code when you create the axes and use this handle instead of
gca
.
所以,在这种情况下,我建议这样:
figure(1);
x = linspace(0,2*pi);
plot(x,sin(x));
ax1 = gca;
ax1.NextPlot = 'add';
figure(2);
plot(ax1,x,cos(x));
无论图形顺序或用户引起的焦点如何,这都会将绘图添加到指定的轴。