Connecting two data points in a plot with a line, and determining this line's slope
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have an excel sheet of a lot of data points (X and Y coordinates), and I have inserted these data into matlab and plotted the figure.
On the figure, I want to connect one data point to another one, and then determine the slope of this line.
It is easy to just write down the coordinates of the two data points and calculate the slope, but I cannot do it manually like this because I have to do it many times for different data points.
Is it possible to do it on the figure to immediately get the line and its slope?
1 Kommentar
dpb
am 20 Jan. 2023
Of course it is, but you've got to have some way to determine which two specific points; the Clairvoyant Toolbox™ is yet to be released...
Akzeptierte Antwort
dpb
am 20 Jan. 2023
Verschoben: dpb
am 20 Jan. 2023
For just between two points, may as well just use
m=(y2-y1)./(x2-x1); % slope between two points
Or, if specify by choosing two indices, then if the two indices are i1, i2 use
m=(y(i2)-y(i1))./(x(i2)-x(i1)); % slope between two points, i1 and i2 indices
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!