MATLAB Answers

markers not getting joined in plot

5 views (last 30 days)
I came across strange problem in matlab, i did a simple line plot using following code in a loop. i want to draw the line joining the markers. in principal it ishing , but the plot is just showing markers not joined by the line. I also t style property seperately, but did not work. Wonder what is preventing matlab to draw the line in plot
Sumera Yamin
Sumera Yamin on 27 Aug 2020
i see your point. It is true, i am plotting scalar values in a loop. Many thanks for your answer. @ Stephen, i am not getting the option to accept your answer

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 27 Aug 2020
Edited: Stephen Cobeldick on 27 Aug 2020
You are plotting scalar values in a loop, which will show individual markers unconnected by a line.
If you want to have markers joined by lines then you must provide plot with vectors/matrices of data.
In practice this means
  • within the loop use indexing to add the data to a vector/matrix,
  • after the loop call plot once with that complete vector/matrix.
Steven Lord
Steven Lord on 27 Aug 2020
Another alternative would be to create an animatedline before the loop and addpoints to it inside the loop.
axis([0 360 -1 1]);
h = animatedline;
for x = 0:360
addpoints(h, x, sind(x))
drawnow expose
You can specify property values for animatedline like Marker, LineStyle, Color, etc. when you create it.

Sign in to comment.

More Answers (1)

KSSV on 27 Aug 2020
hold on
KSSV on 27 Aug 2020
x = 1:10 ;
y = rand(size(x)) ;
Show the output.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!