unable to perform tracking

2 次查看(过去 30 天)
Chris Ron de
Chris Ron de 2020-5-29
Hi,
I am pretty new with MATLAB and I want to link datapoints of different tracks to each other. I do have a file with data that I can change into x, y and z coordinates within a while1-loop. What I wanted to do is comparing each new set of datapoints with the already existing datapoints to see if they can be seen as a next point in an existing track. If that is not possible, the new datapoints are the start of a new track.
I tried to do it with vectors and structs, but no luck so far. The initial dataset is attached to this question and I am wondering if there is someone who can help me out in taking the right steps to a solution.
What I do have so far is:
clc;
clear variables;
f = fopen('combined4.tr','r');
%The current state of each track is in a matrix, showing the last value
A = zeros(6,4);
x_plot = []; % make vector for storing x-values
y_plot = []; % make vector for storing y-values
z_plot = []; % make vector for storing z-values
time = []; % make vector for storing time values
heading = []; % make vector for storing heading values
elevation = []; % make vector for storing elevation values
distance = []; % make vector for storing distance values
speed = []; % make vector for storing speed values
acc = []; % make vector for storing acceleration values
i_values = []; % make vector for storing i-values
while 1
%Read line
line = fgetl(f);
if ~ ischar(line), break, end
row = str2num(line);
t = row(1);
h = row(2);
e = row(3);
d = row(4);
r = cosd(e) * d;
x = sind(h) * r;
y = cosd(h) * r;
z = sind(e) * d;
if A(1,1)==0
A(1,1)=x;
A(1,2)=y;
A(1,3)=z;
A(1,4)=t;
else
for i=1:size(A,1)
difference=sqrt((x-A(i,1))^2+(y-A(i,2))^2+(z-A(i,3))^2);
if difference > 150
A(i,1)=x;
A(i,2)=y;
A(i,3)=z;
A(i,4)=t;
else
A(end+1,1)=x;
A(end+1,2)=y;
A(end+1,3)=z;
A(end+1,4)=t;
end
end
end
end
fclose(f);

回答(1 个)

Gaurav Garg
Gaurav Garg 2020-6-8
Hey Chris
You would want to run 2 loops -
  1. Iterating over all the datapoints,
  2. Running over the datapoints assigned to tracks already
Here on, i would assume each new track being represented with a new row and each column representing the datapoints on the track.
While iterating over each datapoint, you can check whether this datapoint -
  1. should be make a new track, or
  2. should be a part of an existing track.
In case, the datapoint should make a new track, you can add a new row to your matrix, representing a new track.
If it comes to be a point on an existing track, you can add this datapoint to a new column in the respective row/track.
  3 个评论
Gaurav Garg
Gaurav Garg 2020-6-12
Hey Chris,
'If I understood it right, another if statement is necessary within the while1-loop, or can this also be done by adding an elseif statement?' ==> Which loop are you talking about? Because the first loop is used only to iterate over the datapoints on the track, and second one would be used to check the datapoint already assigned (matrix in your case), and no assignment would be needed in the first loop (because you are checking for the right tracks and the respective checkpoints in the second loop).
'Is there a more elegant way to solve this problem' ==> What you are doing here is quite elegant in its own way. You can try other ways as well, which would work , however they would still give you the same performance (time-wise).
Chris Ron de
Chris Ron de 2020-6-12
Hi Gaurav,
I think you hit the right button. I was thinking that it all could be done with one if statement and I was wondering why the while loop and the if statement are not working together. I am going to introduce another if statement and I think I have to make it with true and false statements of the first loop. At this moment it is just a thought and I have to figure it out because I'm not that familiar with MATLAB. Thanks anyway so far and if you have an idea about coding that true and false story, it is more than welcome.
Chris

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by