How to plot all results in a for loop?

1 Ansicht (letzte 30 Tage)
NIANNIAN
NIANNIAN am 3 Nov. 2014
Beantwortet: Image Analyst am 3 Nov. 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*');

Akzeptierte Antwort

Image Analyst
Image Analyst am 3 Nov. 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]);

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by