Remove line between first and last point on plot

I am plotting data from a text file, however, the plot automatically connects the first and last points. How do I get rid of this line?
data = load('data.txt');
time = data(:,1);
avg = data(:,2);
plot(time, avg)

 採用された回答

manateejoe
manateejoe 2015 年 7 月 14 日

2 投票

I was able to figure it out: I had to sort my data:
[time, dum] = sort(time);
avg = avg(dum);

その他の回答 (1 件)

Honglei Chen
Honglei Chen 2015 年 7 月 14 日

0 投票

Are you sure your last point and first point are not the same? If they are, simply do
plot(time(1:end-1),avg(1:end-1))

2 件のコメント

manateejoe
manateejoe 2015 年 7 月 14 日
No, they are different: first point: 371.447, last point: 380.805. With this method, I still get the line in between
Star Strider
Star Strider 2015 年 7 月 14 日
See if:
time = [data(:,1); NaN];
avg = [data(:,2); NaN];
improves the plot.
If your data.txt file is not too large, attach it (use the ‘paperclip’ icon). Without it, it is only a guess as to what the best solution is.

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

カテゴリ

タグ

質問済み:

2015 年 7 月 14 日

回答済み:

2015 年 7 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by