plot a snake graph

5 views (last 30 days)
Harry S
Harry S on 18 Mar 2019
Edited: Harry S on 18 Mar 2019
How to plot a continuous graph on X-Y plane which follows pattern like
x=0:1:10; y=0;
plot (x,y);
hold on;
then y=0.1; x=10:-1:0;
plot (x,y);
hold on;
.
.
.
.
.
upto y=10; x=10; % the plot should look like a snake
  2 Comments
KSSV
KSSV on 18 Mar 2019
How about using sin?
Harry S
Harry S on 18 Mar 2019
Edited: Harry S on 18 Mar 2019
I want my plot to be in this manner with equal spacing

Sign in to comment.

Accepted Answer

KSSV
KSSV on 18 Mar 2019
Play around with this:
x = 1:100 ;
y = 1:100 ;
ind1 = reshape(y,5,[])' ;
y(ind1(1:2:end,:)) = -0.5 ;
y(ind1(2:2:end,:)) = 0.5 ;
plot(y,x)
xlim([-1 1])

More Answers (0)

Categories

Find more on Graph and Network Algorithms 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!