![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174725/image.png)
How to devide a line passing through two points into equal segments?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Soroush Asarzadeh
am 21 Jul. 2016
Beantwortet: Star Strider
am 21 Jul. 2016
Hello, I have two points: (x1,y1) and (x2,y2). Now I want to devide the line passing through these two points into 'n' equal segments. Unfortunately the 'linspace' can just be applied to horizontal and vertical lines! Does anybody have an idea?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 21 Jul. 2016
Coimbine linspace and interp1:
x = [1 5]; % Create Data
y = [3 1]; % Create Data
N = 3; % Number Of Segments
xi = linspace(x(1), x(2), N+1); % Interpolation Vector
yi = interp1(x, y, xi, 'linear'); % Find ‘yi’ For Each ‘xi’
figure(1)
plot(x, y, '-or')
hold on
plot(xi(2:end-1), yi(2:end-1), 'bp')
hold off
grid
axis([0 6 0 4])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174725/image.png)
0 Kommentare
Weitere Antworten (1)
dpb
am 21 Jul. 2016
For straight line it doesn't matter; just divide dx, dy by the number of intervals.
xpts=linspace(x(1),x(end),N);
ditto for y.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!