I want to make a continuous sine function

9 views (last 30 days)
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
Hayeon Chae
Hayeon Chae on 16 Feb 2023
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

Dyuman Joshi
Dyuman Joshi on 16 Feb 2023
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

Find more on Language Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!