Info
This question is closed. Reopen it to edit or answer.
How do I calculate the distance between 3D coordinate points using cell array?
1 view (last 30 days)
Show older comments
Hi,
I am trying to find the distances between pairs of 3D coordinate points. I have a cell array as my data set. Inside each cell there are 6 columns of cells with 2 rows. Each column of cells represents a dimension (XYZ) and each row of cells represents a participant. The following columns are important here:
position_a = [x1 y1 z1];
position_b = [x2 y2 z2];
x1 = windowed_data{1,1}(:,1);
y1 = windowed_data{1,1}(:,2);
z1 = windowed_data{1,1}(:,3);
x2 = windowed_data{1,1}(:,4);
y2 = windowed_data{1,1}(:,5);
z2 = windowed_data{1,1}(:,6);
I am looking to create a new cell array in the same form of the original windowed_data with all the distances between all the elements in x1,y1,z1 and x2,y,z2 using the following formula:
distance_data = sqrt(sum((position_a - position_b) .^ 2))
As an example, the output I am aiming for should look like this:
distance_sample = distance_data{1,1}{1,1}(:,1);
=
distance_data = sqrt(sum((position_a_sample - position_b_sample) .^ 2))
position_a:sample = [x1_sample y1_sample z1_sample];
position_b_sample = [x2_sample y2_sample z2_sample];
x1_sample = windowed_data{1,1}{1,1}(:,1);
y1_sample = windowed_data{1, 1}{1, 2}(:,1);
z1_sample = windowed_data{1, 1}{1, 3}(:,1);
x2_sample = windowed_data{1,1}{1,4}(:,1);
y2_sample = windowed_data{1, 1}{1, 5}(:,1);
z2_sample = windowed_data{1, 1}{1, 6}(:,1);
How would I go about doing this for the entire data set (each row of cells)? Apologies in advance if some parts of this question are redundant or incorrect. I hope its clear what I am trying to do.
Thanks for the support!
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!