Calculating the distance between two points and set lambda depending on the distance

조회 수: 9 (최근 30일)
function [xnew,ynew]=koordinaten_interpolieren(xwert,ywert)
sz = size(xwert); % the size of my coordinates
Xi = [xwert,ywert];
distance= size(xwert);
for i=1:sz-1 % the first thing is to calculating the distance but Error Message:
% Index in position 2 exceeds array bounds (must not exceed 1).
distance= (sqrt((xwert(i,1)-xwert(i+1,2)).^2)) + (sqrt((ywert(i,1)-ywert(i+1,2)).^2));
if abstand(i,1) > 15 % if the distance is very long -> i want to step with 0.2
Lambdastep = 0.2;
else
Lambdastep = 1; % if the distance is low -> you don't need so much points so i go with 1 ?
end
Lambda= 0:Lambdastep:distance; % the points i want to plot is with every two points -> that means on the distance between two points ->
% there will be more points
end
sz_l=size(l,2);
xt = zeros(sz_l*(sz(1)-1),2);
for i=1:sz-1
for j=1:sz_l
xwertt=Xi(i,1) + Lambda(j)*(Xi(i+1,1) - Xi(i,1));
ywertt=Xi(i,2) + Lambda(j)*(Xi(i+1,2) - Xi(i,2));
xt((i-1)*d+j,1)= xwertt;
xt((i-1)*d+j,2) =ywertt;
end
end
xnew = xt(:,1)
ynew = xt(:,2)
end
%any ideas to make it better and what can i do against the error message ?
  댓글 수: 10
Jan  Nabo
Jan Nabo 2019년 11월 13일
yeah it works, i am so proud that you all comment !!!
thank you very much for that i am new in mathlab :D
Jan  Nabo
Jan Nabo 2019년 11월 13일
편집: Jan Nabo 2019년 11월 13일
function out = Randerzeugen(xwert,ywert,X,Y,isInside,block1,randdicke)
if size(xwert,1)<10 % für Koordinaten -> die unter 10 Punkte haben
[xwert,ywert] = koordinaten_interpolieren(xwert,ywert);
end
sz_x=size(xwert,1);
out=false(size(X));
if (~isInside == true)
for i=1:sz_x
out=out | ((((X-xwert(i)).^2)+((Y-ywert(i)).^2))<= randdicke*2);
end
elseif (isInside == true)
block1=~block1;
for i=1:sz_x
out=out | (((X-xwert(i)).^2)+((Y-ywert(i)).^2) <= randdicke*2);
end
end
out= and(out,block1);
end
function [xnew,ynew]=koordinaten_interpolieren(xwert,ywert)
sz = size(xwert,1);
Xi = [xwert,ywert];
xnew=0;
ynew=0;
for i=1:sz-1
distance= sqrt(( xwert(i,1) - xwert(i+1,1) ) ^2 + ( ywert(i,1) - ywert(i+1,1) )^2);
distancesize= 1/distance; %Abstandsberechnung zwischen zwei Punkten um später Lambda festzulegen
Lambda{i} = 0:distancesize:distance; %Alle Abstände zwischen zwei Punkte werden in einem Array gespeichert
end
for i=1:sz-1
xt(:,2) = size(Lambda{i},2);
end
for i=1:sz-1
sz_l = size(Lambda{i},2);% um schon festzulegen wie groß unser "Vektor" ist, um die Werte nicht immer zu überschreiben
for j=1:sz_l
xt(j,1)= Xi(i,1) + Lambda{i}(j)*(Xi(i+1,1) - Xi(i,1)); %neue Werte werden berechnet mit Lambda(Abstände zwischen zwei Punkten
xt(j,2)= Xi(i,2) + Lambda{i}(j)*(Xi(i+1,2) - Xi(i,2));
end
xnew = xt(:,1); % Neue Werte werden übergeben die in xt eingespeichert sind
ynew = xt(:,2);
end
end
is that possible to give the whole Lambda size for my matrix xt? example there are 4 array cells that for
each cells (1x203 for example for the first cell and so on)
i want that because in xnew= xt(:,1); i overwrite the values from xt to xnew without
knowing the size.
so i wrote for example xt = size(Lambda) but that is wrong it would be only give me the size 4.
the reason why i want to do that because i can establish the size of my "future" matrix xt.
so i can change the line xnew = xt(:,1)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by