Filter löschen
Filter löschen

Determine distance between point from a data table

6 Ansichten (letzte 30 Tage)
Constance Woodman
Constance Woodman am 20 Feb. 2018
Kommentiert: Jan am 23 Feb. 2018
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 Kommentare
Jan
Jan am 21 Feb. 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.
Constance Woodman
Constance Woodman am 21 Feb. 2018
Location is x and y on a 255 point grid.
I'm using read table now! (Usually I pull data from memory chips in a really specific way, so outside of that I'm a Matlab newbie!)
Okay, I havent used these functions beofre so I'm making little prototypes of code blocks and testing them on mini data tables. Thank you!!
What confused me about diff is pulling x and y line one and then x and y line two and finding the distance. I am unfamiliar with all diff can do!

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Peter Perkins
Peter Perkins am 21 Feb. 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.

Constance Woodman
Constance Woodman am 23 Feb. 2018
Bearbeitet: Constance Woodman am 23 Feb. 2018
Problem B, finding distance:
So people are using a neuronal mapping tool to find distances between x,y pairs.
It kinds of sucks because "dist" finds the differences between all points, creating an ENORMOUS matrix and then people only use the first column.
So if i create a 13x2 double and run dist I get a Big Ugly Matrix
Dist = dist(unnamed(:,1:2)')
There is no way I can efficiently run my 2 million x,y pairs this way.
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'm not pasting code because I don't want to perpetuate problematic code.
points = [0 0; 0 0; 0 1; 0 0; 1 0; 0 0; 0 300; 0 0;1, 2];
Diff = [diff(points, 1); points(end, :)-points(1, :)];
Dist = sqrt(sum(Diff .* Diff, 2));
Now I need to address problem A, and make it read from a table.
So, I create and import a text table to represent my 400 MB x,y table but I don't import is at a table, BOOM, DONE, just import as a matrix, save a step.
Using Jan's code, I change "points" to the name of my data matrix ("miniData") and I get a stupid, wonderful, distance table.
So now, I try for realsies.
I learned the hard way not to format data column during import, such as the datatype "datetime", or stuff will screw up. I leave all the data types "numbers" and don't try to add headings during import. Then I wait a couple minutes while it warns me that I may require more memory than the system has to complete the import.
But, DUN DUN DUUUUN
I only need column 6 and 7, which are my x and y values, the above successful formula will use columns I don't want to be included. To be continued...
  1 Kommentar
Jan
Jan am 23 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by