I want to make a continuous sine function

this code keeps plotting points but I want a smooth continuous line…How do I do that?
for x = -3*pi:pi/10:3*pi
if sin(x) > 0
y = sin(x);
else
y = 0;
end
plot(x, y);
end

2 Comments

for x = -6*pi:pi/10:6*pi
if sin(x) > 0
y = sin(x);
else
y = 0;
end
plot(x, y, 'bo');
end

Sign in to comment.

 Accepted Answer

x = -6*pi:pi/10:6*pi;
y = sin(x);
f = max(sin(x),0);
plot(x, f, 'b-o') %remove o if you don't want markers
ylim([-0.2 1.2])

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!