using a figure in a for loop for different figures
Mostrar comentarios más antiguos
When I try to plot different figures in a for loop, the last figure is plotted for all three figures. I tried interchanging the loops but the results are the same. How can i achieve this?
Also, I have a second question. I would like the title to read title('$$\omega = omega$$', 'interpreter', 'latex') but this doesn't yield \omega = 5, 6.1, and 5.9 for the three figures. I also tried title('$$\omega = $$' omega, 'interpreter', 'latex') but mixing doesn't work at all.
% constants similar to three plots
delta = 0.1; % F0/k deflection of mass under a force F0
% static deflection
omegan = 6; % natural frequency
x0 = 0.1; % initial displacement
dotx0 = 0.5; % initial velocity
t = (0:0.001:5); % time vector
for omega = [5, 6.1, 5.9]
x = x0*cos(omegan*t) + dotx0/omegan*sin(omegan*t) + delta*...
(cos(omega*t) - cos(omegan*t))/(1 - (omega/omegan)^2);
for i = [1, 2, 3]
figure(i)
plot(t, x)
xlabel('time, t')
ylabel('displacement, x(t)')
%title('$$\omega = $$' omega, 'interpreter', 'latex')
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!