How Can I Create More Than One Figure

734 ビュー (過去 30 日間)
Nathan
Nathan 2014 年 3 月 1 日
コメント済み: Image Analyst 2025 年 11 月 14 日 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?

採用された回答

Image Analyst
Image Analyst 2014 年 3 月 2 日
編集済み: Image Analyst 2025 年 1 月 25 日
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 件のコメント
Dan
Dan 2025 年 11 月 9 日 20:04
編集済み: Dan 2025 年 11 月 9 日 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 2025 年 11 月 14 日 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');

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 1 日
編集済み: Azzi Abdelmalek 2014 年 3 月 1 日
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 件のコメント
Michael
Michael 2025 年 1 月 25 日
I thnk he meant he wanted two different windows
Nathan
Nathan 2025 年 1 月 25 日

Oh yeah, I think so too

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by