Subplots in a loop while the graphs keep changing

조회 수: 7 (최근 30일)
SBRANS
SBRANS 2018년 11월 25일
댓글: SBRANS 2018년 11월 25일
I have several for loops working at the same time and I would like each graph to be plotted in a figure with 4x3 plots. This is what I have now
There are 4 different values for b and 3 for F.
for i = 1:length(b)
b_loop = b(i);
for j = 1:length(F)
F_loop = F(j);
for n=1:N
tbar = t(n)+h/2;
ybar = y(n)+(h/2)*(dy(n));
dybar = dy(n)+h/2*((F_loop*cos(w(1)*t(n)))/m-(b_loop*dy(n)/m)-(w0^2*y(n)));
y(n+1) = y(n)+h*(dybar);
dy(n+1) = dy(n)+h*((F_loop*cos(w(1)*t(n)))/m-(b_loop*dybar/m)-(w0^2*ybar));
t(n+1) = t(n)+h;
end
subplot(4,3, ????)
plot(t,y, t,dy)
title(sprintf('F = %d, b = %d', F(j), b(i)))
xlabel('Time [s]')
ylabel('Position [m] & Velocity [m/s]')
legend('position', 'velocity')
end
end
When I use "figure" instead of "subplot" I get the 12 graphs that I want in 12 different windows, but I want each graph that comes out to be placed in one windows also it the right subplot.

채택된 답변

Image Analyst
Image Analyst 2018년 11월 25일
One simple way is to put a counter in there
counter = 1
for i = .......
for j = .......
subplot(4,3, counter);
counter = counter + 1;
end
end
Alternatively you can compute it from i and j
subplot(4,3, length(b) * (i-1) + j)

추가 답변 (0개)

카테고리

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