Is it possible to plot the output plot of multiple function on the same figure?
5 次查看(过去 30 天)
显示 更早的评论
This is what the function looks like and I have multiple sets of inputs. I was wondering if there was anyway to have the output plots of multiple functions on the same figure? If not, I will have to edit the function to have more inputs and then plot them inside the function.
function obj(Ycord,Xcord,Yvel,Xvel)
for k=1:length(Ycord)
clf
for i=1:5
hold on
grid on
plot(-Xcord(k,i),Ycord(k,i),'.');
quiver(-Xcord(k,i),Ycord(k,i),-Xvel(k,i),Yvel(k,i),'LineWidth',1);
rectangle('Position',[-1 -1 2 4],'EdgeColor', 'm','LineWidth',2);
rectangle('Position',[-Xcord(k,i)-1,Ycord(k,i),2,4],'EdgeColor','k','LineWidth', 1);
end
xlim([-40, 40]);
ylim([-40, 40]);
pause(0.1)
end
end
0 个评论
回答(1 个)
Walter Roberson
2022-6-14
generally speaking you can use "hold on" or use subplot() or tiled layouts. However none of those will work for you as long as you keep that clf that is erasing everything in the figure
2 个评论
Walter Roberson
2022-6-14
MATLAB has "high level" and "low level" graphics calls.
If you call the right functions with the right parameters, then MATLAB does not check the graphics state and just adds the new graphics to whatever is there.
But most graphics calls are considered to be "high level" calls. They check the NextPlot property of the axes, and if it is set to Replace, then the graphics call clears the axes before drawing. "hold on" sets the NextPlot property to Add instead of Replace.
Notice that nothing in this is checking to see whether the graphics calls were made inside the same function. The system only cares about the current setting of NextPlot.
It is therefore completely valid to set hold on, and then make any number of function calls that eventually add graphics. As long as those functions do not clear the figure or clear the axes or turn off the hold or deliberately delete graphics, then the graphics will just keep building up, no matter which function makes the graphics call.
But.. clf removes all current graphics in the figure.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!