Subplots in a loop while the graphs keep changing

8 ビュー (過去 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)
  1 件のコメント
SBRANS
SBRANS 2018 年 11 月 25 日
Yes the counter did it! Thanks!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by