Unable to retain existing plot when I run the program again with different parameter value
2 次查看(过去 30 天)
显示 更早的评论
I am required generate a matlab plot showing center of ellipse with different values of delta. Delta = 0 to 0.1 at intervals of 0.02. First I run the program with delta = 0.0. Then I run the program again with delta = 0.02. However, I could not get the result for both delta = 0.0 and delta = 0.02 in the same plot.
figure
plot (x,y,'k*','DisplayName','\delta = 0.0)
hold on
xlabel('\it{y}','FontName','Times','FontSize',36)
ylabel('\it{x}','FontName','Times','FontSize',36)
set(gca,'FontName','Times','FontSize',18)
ax = gca;
ax.YDir = 'reverse';
legend ('location','southeast')
axis('square');
set(gcf,'Position',[100 100 550.4 550.4]);
回答(1 个)
Piyush Dubey
2023-10-6
编辑:Piyush Dubey
2023-10-6
I understand that you are having issues while attempting to plot multiple ellipses with different delta values in the same figure.
The MATLAB command "figure" creates a new figure window with default property values. Hence, whenever the code is re-run with a new delta value, a new figure window with its corresponding plot is created.
To overlay multiple plots in the same figure, the delta values should be updated in the same execution session. To achieve this consider turning on the "hold" feature immediately after declaring the figure followed by a "for" loop to iterate over the delta values. Thus, by enabling the "hold" feature, all the plots will be plotted on the same figure since they are part of the same execution session.
The following code snippet demonstrates the use of "hold" to create multiple plots on the same figure:
figure
hold on
% for loop iterates over delta values and plots them simultaneously on the figure
for delta = 0.0:0.02:0.1
plot(x, y, 'k*', 'DisplayName', '\delta = 0.0')
end
Please refer to the following MathWorks documentation link for more information on “Combining Multiple Plots”:
Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!