user2861089
user2861089

Reputation: 1235

The appearance of a dashed line in matlab is not even

The appearance of a dashed line in matlab is not even. For example:

x = [121.2802 112.5784 115.0855 109.0412 99.1158 103.9001];
y = [-25.8392 -24.9378 -25.1976 -24.5714 -23.5433 -24.0389];

plot(x,y,'--k','linewidth',1.2)

print -r600 -dtiff test.tif

The dashes do not appear separate in some parts of the line. Is this because the points are not evenly distributed? Any suggestions? Thanks.

Upvotes: 1

Views: 176

Answers (1)

The Minion
The Minion

Reputation: 1164

No the problem isn't matlab it is your variables. Matlab is conecting (x(i),y(i)) with (x(i+1),y(i+1)) with a dashed line. But your data isn't sorted.
The only thing happening here is that you draw 2 lines above each other which results in your non dashed parts. If you want only dashed line try sorting your data before plotting it.

Edit 1

z= [x' ,y'];
z= (sortrows(z))';
x2=fliplr(z(1,:));
y2=fliplr(z(2,:));
plot(x2,y2,'--k','linewidth',1.2)

Here is a way to sort your data. What i am doing is i am conecting x,y rowwise in z. Then i use sortrows to sort all rows according to the first one. Then i transpose the resulting matrix so that you have new coloumn vectors. After that i use fliplr to flip the first to last element and so on (inverting your data, since your original data went from 120 to 100and i don't know if you want to use the data later on). And then i plot it.
Hope that helps
Edit 2
As posted by Dennis:

z= [x' ,y'];
z= (sortrows(z))';
z=flipud(z);
plot(x2,y2,'--k','linewidth',1.2)

Upvotes: 2

Related Questions