Plot function adding line from last point in row to origin

Hello,
I currently have a plot that looks like this:
and I am trying to remove the line that is connecting the last node in the row to the origin. I know this question has been asked before but I was unable to use the answers to solve my problem. I tried sorting the data and tried stating LineStyle to none but it didn't work. Here is what I have so far:
plot(transpose(x_nudged),transpose(y_nudged),'-')
x_nudged(x_nudged==0)=nan;
y_nudged(y_nudged==0)=nan;

1 Comment

Remember that changing your data after you plot is not going to affect your plot.

Sign in to comment.

 Accepted Answer

In order to see that plot with multiple lines, your y_nudged must be 2D. The following code takes that into account.
xt = x_nudged.';
if isvector(xt)
xt(end) = [];
else
xt(end,:) = [];
end
yt = y_nudged.';
if isvector(yt)
yt(end) = [];
else
yt(end,:) = [];
end
plot(xt, yt);

7 Comments

Thanks Walter, worked perfectly! One question however, in my old graph, I was able to cut off the x coordinates at 15. Thus, my boundary was at x = 0 and then x = 15. However, when I inputted your code, I am seeing boundary at x = 0 but not at 15. Is there a way to add this into the code?
For example, the last point on the x axis being plotted is 14.8 but it should extend to 15.
Can you attach your data as a .mat for testing?
Sure, see attached. The matrices I am using are x_coor and y_adj.
Hi Walter. I was wondering if you had any updates on the situation. I notcied that when I tranpose my matrix, it doesn't catch the last column. So my original matrix of 18x76 is getting transposed into 75x18.
That code does not join back to the origin the way you were describing earlier, so the deletion of points should not be done.
However, your maximum x alternates between 15.0 and 15.1 in odd and even columns, so it is not immediately clear whether you want your maximum plotted to be 15 or 15.1
xt = x_coor.';
yt = y_adj.';
plot(min(xt, 15), yt)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!