Not all Subplots are plotting

조회 수: 16 (최근 30일)
Lilly
Lilly 2014년 5월 26일
답변: Sara 2014년 5월 26일
This is my function: Only the last subplot is plotting. I have been passing in: hold on first(0, 10, 0.1, 4);
function first(start, finish, a, h)
%Declare initial values with respect to the function. x =start:h:finish; y = zeros(1, length(x)); y(1) = 1; n=1;
%To create as many subplots as there are increment values (and later, one more for the analytical solution): for j = 1:a
%Change h to change increment for each subplot.
if j>=2
h=h/10;
end
while x(n)<=finish
%while x value does not exceed the maximum x value
y(n+1) = y(n)+(-4 * (x(n).^3) * (y(n).^2))*h;
% x(n+1) = x(n) + h;
n = n+1;
end
print j
xlabel('x axis')
ylabel('y axis')
title('Graph')
subplot(5, 1, j); plot(x, y, '--')
end
%Now compare with analytical solutions: y(x) = 1/(x^4+1). subplot(5, 1, 5); x =start:0.1:finish; yaccurate = 1\(x.^4 +1); xlabel('x axis') ylabel('y axis') title('Analytical Solution') plot(x, yaccurate, 'g')
hold off

답변 (1개)

Sara
Sara 2014년 5월 26일
you have for j = 1:a with a = 0.1, i.e. it never enters the loop

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by