Subplots in a loop while the graphs keep changing
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SBRANS
el 25 de Nov. de 2018
Comentada: SBRANS
el 25 de Nov. de 2018
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.
0 comentarios
Respuesta aceptada
Image Analyst
el 25 de Nov. de 2018
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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!