Length of a plotted line

6 views (last 30 days)
Frederik Reese
Frederik Reese on 7 Jun 2022
Commented: Frederik Reese on 7 Jun 2022
Hi, I have plots like this:
I want to know, how I can get the length of the lines in the x axis in the plot. Is there a function or can anyone write a code for me ?

Accepted Answer

Matt J
Matt J on 7 Jun 2022
Edited: Matt J on 7 Jun 2022
h=plot(2:6);
xlength = h.XData(end)-h.XData(1)
xlength = 4
  3 Comments
Matt J
Matt J on 7 Jun 2022
If you download the files from here, it's a simple modification
h=plot([2:4,nan,5:7]);
[start,stop]=groupLims(groupTrue(~isnan(h.YData)),1);
xLength=sum( h.XData(stop)-h.XData(start) )
xLength = 4
Frederik Reese
Frederik Reese on 7 Jun 2022
thanks for your great help.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!