Determine distance between point from a data table
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
My collaborator sent me a HUGE 200mb table of data as a TXT. I can import it fine, phew.
Column 6 and 7 are X and Y coordinates.
I want to figure out the delta/change in distance between row 1 and row 2, row 2 and row 3, etc. We want to see how far a bird moves each second.
My attempts are laughably crappy.
Problem A: Transforming the table data to formats that functions (like "dist") can use, like a matrix or something. Problem B: Setting up a loop to find the positive distance change for each row and the one below it, then write it to a new array or somesuch.
2 comentarios
Jan
el 21 de Feb. de 2018
Please explain how the data is available in Matlab. Did you use readtable? You do not need a loop, a simple diff command is sufficient.
Respuestas (2)
Peter Perkins
el 21 de Feb. de 2018
It sounds like maybe you used readtable. For the kind of calculation you're doing, I imagine you'll need a numeric array. Simple: X = table2array(T).
I'm gonna assume that your data are something like geographic locations, and you want either distance from point to point, or from origin to point, and that your distance is something like Euclidean. Given that, get the successive differences as Y = X(2:end,:) - X(1:end-1,:), and then something like vecnorm on the rows of Y. Or on the rows of Y = X - origin.
This is all guesswork.
0 comentarios
Constance Woodman
el 23 de Feb. de 2018
Editada: Constance Woodman
el 23 de Feb. de 2018
1 comentario
Jan
el 23 de Feb. de 2018
"Problem B"? Is this a new problem? If so, please open a new thread instead of inserting it in the section for answers.
I admit, that I still do not understand, what your question is.
Several implementations of diff I've seen on the Matlab answers
forums work until the coordinate is a double-digit, then it
thinks that "10" is "1" and screws up distances majorly
I do not understand, what this means. There are no "implementations of diff", but diff is a built-in Matlab command, which does not care about the number of digits at all.
Diff = diff(points(:, 6:7), 1);
Dist = sqrt(sum(Diff .^ 2, 2));
With:
Diff = [diff(points, 1); points(end, :)-points(1, :)];
the distance between the last and the first point was considered also. Maybe you want just the distances between the rows.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!