How Can I Create More Than One Figure

707 visualizaciones (últimos 30 días)
Nathan
Nathan el 1 de Mzo. de 2014
Comentada: Image Analyst el 14 de Nov. de 2025 a las 5:02
I can tell Matlab to make a basic figure such as a plot of 'x' versus 'y', but when I tell Matlab to make more than one figure in the same script, it will delete my first figure when it makes the next one. Do I need to tell Matlab to save each figure after it creates it and before making the next one? or am I missing something very obvious?

Respuesta aceptada

Image Analyst
Image Analyst el 2 de Mzo. de 2014
Editada: Image Analyst el 25 de En. de 2025
Something like this to put data into different axes on the same figure window:
% Make plots in a 2 by 2 arrangement on the currently displayed figure window.
subplot(2,2,1); % Upper left
plot(1:10);
subplot(2,2, 2); % Upper right
bar(1:20);
subplot(2,2,3); % Lower left
imshow('cameraman.tif');
subplot(2,2,4); % Lower right
scatter(rand(20,1), rand(20,1));
Or something like this to put data into two separate figure windows:
% Instantiate data.
x = 1:10;
y1 = rand(1, 10);
y2 = sin(x);
% Now plot in a new figure window:
hFig1 = figure('Name', 'This is the first window');
plot(x, y1, 'b.-', 'LineWidth', 3, 'MarkerSize', 30);
grid on;
ylabel('Y1', FontSize=25);
title('Y1 vs. X', 'FontSize', 25)
% Now plot in a totally separate figure window:
hFig2 = figure('Name', 'This is the second window');
plot(x, y2, 'r.-', 'LineWidth', 3, 'MarkerSize', 30);
grid on;
ylabel('Y2', FontSize=25);
title('Y2 vs. X', FontSize=25)
  3 comentarios
Dan
Dan el 9 de Nov. de 2025 a las 20:04
Editada: Dan el 9 de Nov. de 2025 a las 20:04
thank you for answering this 11 years after the fact, i was doing an assignment and had the exact same question as nathan lol
Image Analyst
Image Analyst el 14 de Nov. de 2025 a las 5:02
Or you can do this to put both curves into one axes on a single figure window:
% Instantiate data.
x = 0 : 6 * pi;
y1 = rand(1, numel(x));
y2 = sin(x/3);
% Now plot y1 in a new figure window:
hFig1 = figure('Name', 'This is the only window');
plot(x, y1, 'b.-', 'LineWidth', 3, 'MarkerSize', 30);
grid on;
% Now plot y2 in the same axes in the same figure window:
hold on; % This is the key line to keep the next plot from blowing away the first plot.
plot(x, y2, 'r.-', 'LineWidth', 3, 'MarkerSize', 30);
xlabel('X', FontSize=25);
ylabel('Y1 and Y2', FontSize=25);
title('Y vs. X', FontSize=25)
legend('y1', 'y2', 'Location', 'southwest');

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 1 de Mzo. de 2014
Editada: Azzi Abdelmalek el 1 de Mzo. de 2014
Use
hold on % many plot in the same figure
Or plot in different figures
figure
plot(x1,y1)
figure
plot(x2,y2)
See also subplot
  2 comentarios
Michael
Michael el 25 de En. de 2025
I thnk he meant he wanted two different windows
Nathan
Nathan el 25 de En. de 2025

Oh yeah, I think so too

Iniciar sesión para comentar.

Categorías

Más información sobre Axis Labels 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