Determine distance between point from a data table
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2018-2-21
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.
回答(2 个)
Peter Perkins
2018-2-21
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 个评论
Constance Woodman
2018-2-23
编辑:Constance Woodman
2018-2-23
1 个评论
Jan
2018-2-23
"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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!