Plotting a second graph on an existing figure

조회 수: 3 (최근 30일)
aviv kadair
aviv kadair 2018년 4월 10일
편집: Birdman 2018년 4월 10일
Hello,
In a specific exercise, I was meant to first show results of a function plotted on a graph, and then plot a second set of results on the previous figure. I did it using a hold on function after the code of the first plot, however, it only ended up presenting both graphs on the same figure, and not show the first graph alone and then both of them. I hope the process is clear :)
if true
% code
%clause c: defining baseline parameters
R=22;
L = 300;
N = [1:3:45];
X = (L.*N)./(R+N);
figure; plot(N, X); xlim([1 45])
xlabel('Number of worms on plate'); ylabel('Number of eggs layed')
title('The link between worms on plate and number of eggs hatched')
hold on
%clause d: input
H = [16 40 69 87 106 131 142 147 166 161 175 180 192 198 194];
plot(N, H); legend('Number of eggs expected','Number of eggs layed');
end

답변 (1개)

Birdman
Birdman 2018년 4월 10일
편집: Birdman 2018년 4월 10일
You need something like this:
R=22;
L = 300;
N = [1:3:45];
X = (L.*N)./(R+N);
figure(1);
plot(N, X);
xlim([1 45])
xlabel('Number of worms on plate'); ylabel('Number of eggs layed')
title('The link between worms on plate and number of eggs hatched')
%clause d: input
H = [16 40 69 87 106 131 142 147 166 161 175 180 192 198 194];
figure(2);
plot(N,X,N,H);
legend('Number of eggs expected','Number of eggs layed');
  댓글 수: 2
aviv kadair
aviv kadair 2018년 4월 10일
ok, so technically it replotted the first graph- as it appears in two different windows.
Birdman
Birdman 2018년 4월 10일
Exactly. Also, two separate figures are defined.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by