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 件のコメント

Walter Roberson
Walter Roberson 2021 年 2 月 23 日
Remember that changing your data after you plot is not going to affect your plot.

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

 採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 23 日

0 投票

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 件のコメント

Radhika Kulkarni
Radhika Kulkarni 2021 年 2 月 23 日
編集済み: Radhika Kulkarni 2021 年 2 月 23 日
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.
Walter Roberson
Walter Roberson 2021 年 2 月 23 日
Can you attach your data as a .mat for testing?
Radhika Kulkarni
Radhika Kulkarni 2021 年 2 月 23 日
Sure, see attached. The matrices I am using are x_coor and y_adj.
Radhika Kulkarni
Radhika Kulkarni 2021 年 2 月 27 日
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.
Walter Roberson
Walter Roberson 2021 年 2 月 27 日
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
Radhika Kulkarni
Radhika Kulkarni 2021 年 2 月 27 日
I want it to be 15.
Walter Roberson
Walter Roberson 2021 年 2 月 27 日
xt = x_coor.';
yt = y_adj.';
plot(min(xt, 15), yt)

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by