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
plot(x,y,'--o')

4 件のコメント

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 8 月 27 日
When trying your example I get the expected dashed line. Perhaps try:
plot(x,y,'o-')
for a solid line.
Sumera Yamin
Sumera Yamin 2020 年 8 月 27 日
somehow, i am not getting any line, solid or dashed, i tried other way round like 'o-', but does not work. with a simple data, it does work, but in my lengthy code, it dont join the points. I wonder if something is preventing plot command to draw a line.
Stephen23
Stephen23 2020 年 8 月 27 日
編集済み: Stephen23 2020 年 8 月 27 日
"I wonder if something is preventing plot command to draw a line."
Your code. My guess is that 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 the unlikely event that you really are calling plot just once then please click the paperclip button to upload the exact data vectors/matrices that you call it with, all saved in one .mat file. And show us the exact code used.
Sumera Yamin
Sumera Yamin 2020 年 8 月 27 日
編集済み: Sumera Yamin 2020 年 8 月 27 日
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

サインインしてコメントする。

 採用された回答

Stephen23
Stephen23 2020 年 8 月 27 日
編集済み: Stephen23 2020 年 8 月 27 日

0 投票

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.

2 件のコメント

Sumera Yamin
Sumera Yamin 2020 年 8 月 27 日
Thanks
Steven Lord
Steven Lord 2020 年 8 月 27 日
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
end
You can specify property values for animatedline like Marker, LineStyle, Color, etc. when you create it.

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2020 年 8 月 27 日

0 投票

plot(x,y,'o',x,y,'-')
Or
plot(x,y,'-o')
Or
plot(x,y,'o')
hold on
plot(x,y)

2 件のコメント

Sumera Yamin
Sumera Yamin 2020 年 8 月 27 日
thanks, tried this. doesnt help
KSSV
KSSV 2020 年 8 月 27 日
編集済み: KSSV 2020 年 8 月 27 日
x = 1:10 ;
y = rand(size(x)) ;
plot(x,y,'-o')
Show the output.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Animation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by