Problems in using the function: line()

I am trying to connect the points of a scatter plot with a line using line(x,y) but the line simply doesn't appear. The vectors are both of the same size. The first one is a linspace vector with 96 elements and the second is a vector with 96 elements obtained from calculations carried on in the main script. How do I connect the points that I obtained from a scatter plot of these two vectors?

回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 5 月 24 日
編集済み: Ameer Hamza 2018 年 5 月 24 日

0 投票

Use this code as a template
x = linspace(0, 100, 100);
y = rand(size(x));
scatter(x, y);
hold on;
line(x, y);
The scatter plot points will be connected.

3 件のコメント

Luca Guarino
Luca Guarino 2018 年 5 月 24 日
Thank you for your answer. Unfortunately I used exactly the same code but in my case the plot only shows the markers and not the lines connecting them. Could it be a problem in my Matlab version?
Stephen23
Stephen23 2018 年 5 月 24 日
@Luca Guarino: please show us the exact code that you are using.
Luca Guarino
Luca Guarino 2018 年 5 月 24 日
I managed to solve the problem. Apparently the width of the line I was using was too small and it didn't appear on the graph. I increased the width and now the problem is solved. It way easier than I thought, sorry for bothering you. And thank you.

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

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

質問済み:

2018 年 5 月 24 日

コメント済み:

2018 年 5 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by