Transfers of given points

1 次查看(过去 30 天)
Hello My name is Vladi,
i need some help with my programm
i want to adjust given x&y-values in such a way that a distance of 100 mm is created at the contour. The x&y-values i read into the system fron an TXT-file.
i dont know how to create this. i tried it like this:
x=[data(:,1)] % regard the first column as x values
y=[data(:,2)] % regard the second column as y values
x_new=[x+100]
y_new=[y+100]
if i plot the curve i have the problem that i hava to much points in the upper an to much points in the lower part
I want to transfer the points exactly vertically so that there is a distance of 100 mm between the contours.

采纳的回答

Walter Roberson
Walter Roberson 2021-4-20
%some sample data for example
data(:,1) = linspace(0, 11000, 500);
data(:,2) = 9500 .* exp(-0.00048 .* data(:,1));
%the work
ncontour = 10;
contour_dist = 100;
x = [data(:,1)]; % regard the first column as x values
y = [data(:,2)]; % regard the second column as y values
minx = min(x); maxx = max(x);
miny = min(y); maxy = max(y);
for K = 0 : ncontour - 1
offset = K * contour_dist;
tx = x + offset;
ty = y + offset;
mask = minx <= tx & tx <= maxx & miny <= ty & ty <= maxy;
plot(tx(mask), ty(mask));
hold on
end
hold off
xlim auto; ylim auto
  7 个评论
Vladimir Eichholz
Vladimir Eichholz 2021-4-21
thanks a lot for this information. now i can solve my problem
Walter Roberson
Walter Roberson 2021-4-22
编辑:Walter Roberson 2021-4-22
My calculation was wrong before.
x = linspace(0, 11000, 100);
y = 9500 .* exp(-0.00048 .* x);
plot(x, y, 'k');
hold on
r = 100;
g = gradient(x, y);
perp = atan(g) + pi/2; %fixed!
xp = x + r * sin(perp);
yp = y + r * cos(perp);
plot(xp, yp, 'b')
hold off
xlim([0 2000])
dists = sqrt((x-xp).^2 + (y-yp).^2);
plot(dists)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by