Determine distance between point from a data table
8 ビュー (過去 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!