1
votes

I am plotting data vs time, however there is a line that connects the first and last points, how do I get rid of this line?

Relevant code:

data = load('AMT_CO2.txt');
time = data(:,1);
avg = data(:,2);
plot(time, avg);

enter image description here plot(time(1:end-1), avg(1:end-1))

Please note that this question has been asked here: Line between first and last point however, this doesn't have an answer

There is also a question: Removing the line between two specific data points in Matlab however, I tried not plotting the last point and I get the same line

1
@ manateejoe Erman Gungor's answer is the right thing to do. Check your data to see if it repeats (x,y) pairs at the end. Matlab would not arbitrarily decide to draw a line between data like this. There has to be a place in your data where the next data point is back at the beginning. - willpower2727

1 Answers

2
votes

Or you could sort the time vector.

[time, dum] = sort(time); avg = avg(dum);

Or remove repeated values:

[time, dum, ~] = unique(time); avg = avg(dum);

However, be careful because the repeated point could be caused by data corruption or something similar.