How to plot all results in a for loop?

1 visualización (últimos 30 días)
NIANNIAN
NIANNIAN el 3 de Nov. de 2014
Respondida: Image Analyst el 3 de Nov. de 2014
I have tried to plot a 2D figure for a for loop function but the results does nor show in one figure?
My code:
function fluid_dynamics
F=input('Enter the inpulse force:');
for x=0:0.1:8*pi;
y1= F*exp(-0.246*x)*sin(0.806*x);
end
figure
plot(x, y1, 'r*');

Respuesta aceptada

Image Analyst
Image Analyst el 3 de Nov. de 2014
You forgot to put an index for y1. Try this:
fontSize = 30;
F=input('Enter the inpulse force:');
x = 0 : 0.1 : 8*pi;
for index = 1 : length(x)
y1(index) = F * exp(-0.246*x(index)) * sin(0.806*x(index));
end
figure
plot(x, y1, 'r*-', 'LineWidth', 3);
xlabel('x', 'FontSize', fontSize);
ylabel('y1', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by