Unable to retain existing plot when I run the program again with different parameter value

2 visualizaciones (últimos 30 días)
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]);

Respuestas (1)

Piyush Dubey
Piyush Dubey el 6 de Oct. de 2023
Editada: Piyush Dubey el 6 de Oct. de 2023
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.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by