unable to perform tracking
Mostrar comentarios más antiguos
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);
Respuestas (1)
Gaurav Garg
el 8 de Jun. de 2020
0 votos
Hey Chris
You would want to run 2 loops -
- Iterating over all the datapoints,
- 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 -
- should be make a new track, or
- 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 comentarios
Chris Ron de
el 10 de Jun. de 2020
Gaurav Garg
el 12 de Jun. de 2020
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
el 12 de Jun. de 2020
Categorías
Más información sobre Digital Filter Analysis en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!