How Can I Create More Than One Figure
728 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nathan
am 1 Mär. 2014
Kommentiert: Image Analyst
am 14 Nov. 2025 um 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?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 2 Mär. 2014
Bearbeitet: Image Analyst
am 25 Jan. 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 Kommentare
Image Analyst
am 14 Nov. 2025 um 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');
Weitere Antworten (1)
Azzi Abdelmalek
am 1 Mär. 2014
Bearbeitet: Azzi Abdelmalek
am 1 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



