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!