How to plot all results in a for loop?

3 次查看(过去 30 天)
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*');

采纳的回答

Image Analyst
Image Analyst 2014-11-3
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]);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by