coonecting line closer to next xy coordinates based on distance

I have attached my XY coordinates and you can see RED and BLUE marked in the picture attached.
I would like to coonect this lines in the similar way, how it appears in picture attached.
Is there any way to do this , if so , can you please do help me out with example code.

Answers (3)

x = pointdbscan.x;
y = pointdbscan.y;
d = sqrt(x.^2+y.^2);
dz = diff(d);
xplot{1}(1) = x(1);
yplot{1}(1) = y(1);
j = 1;
k = 0;
for i = 1:length(dz)
if dz(i) > 20
j = j+1;
k = 0;
end
k = k+1;
xplot{j}(k) = x(i+1);
yplot{j}(k) = y(i+1);
end
figure
ax = axes;
hold(ax,'on')
p = cellfun(@plot, xplot,yplot);
set(p,'color','b')

3 Comments

the solution provided above did not helped , please see the attached
Satya,
you will need to more specific in your question. Is the data you have in centimeters and you want 20 meters? Is the condition 20 meters in one direction?
sorry for that , if my explaination is bad, here i describe my problems below
I have attached 2 figure now , and i have written the comment what is expected in the attached figure.
is there a way to resolve this ? I have no problem in considering large distance also. but it should connect in the way i have represented in attached figure

Sign in to comment.

See my attached edge linking demos. Adapt as needed.

10 Comments

I will look into this code today and provide the feedback whether it works for the given data i have provided in the earlier comments.
Hi,
Unfortunately it did not resolved my problem and it is very very slow which takes atleast 30mins.
Do anyone can help me to write the code to coonect the lines accordingly as specified in the above pic for the data provided ?
your support would be really appreciated.
Your data does not look like what you posted:
s = load('pointdbscan.mat')
x = s.pointdbscan.x;
y = s.pointdbscan.y;
plot(x, y, 'b.', 'MarkerSize', 7);
grid on;
Or, if I plot x and y separately vs. index:
Here is the below pictures which i have plotted with the loaded data
if you zoom in , you will be able to see the difference.
Expect as below for the attached figure
So you're looking at x and y individually vs. index? Do you want the centerline? Did you try movmean(), movmedian(), or sgolayfilt()?
yes excatly i am looking at x and y individually Vs index and i do not need the centerline.
If you need the reference for the centeriod , i have attached further 'VehicleTraj.mat' file where you can scatter this data over the locations data.
I have not tried the methods you have mentioned ,I tried my best but did not successed and therefore i raised this question. Can you please do help me with your code to implement for my data in .mat file i have shared with you pointdbscan.mat.
I would really appreciate your effort if you could resolved it.
Comment posted as flag by SatyaPrakash Gupta:
waiting for your input
@Image Analyst:
I have further reduced the data, please find the attached as below.
In .mat file , you will find x and y coordinates and the vehicle trajectory as show below.
NO , i do not know how to do it , therefore request you suppor to help me out to make to points connected as like below attached

Sign in to comment.

I have made it more simple for you i.e now the data is being separated between left and right, please find the same as attached.
Now is it possible to connect the data on left side and data on right side ?

1 Comment

Comment posted as flag by SatyaPrakash Gupta:
can you help me here please
@SatyaPrakash, please don't use flags for comments.

Sign in to comment.

Categories

Products

Release

R2018b

Asked:

on 9 Apr 2020

Commented:

Rik
on 18 Apr 2020

Community Treasure Hunt

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

Start Hunting!