How do I apply distance formula for 3D coordinate points for all elements in a cell array?

3 views (last 30 days)
lil brain on 13 Feb 2022
Commented: lil brain on 13 Feb 2022
Hi,
I have a cell array where each cell contains a matrix of 3D coordinates (xyz) for three positions (9 columns in total). These are:
head = columns 1-3
left hand = columns 4-6
right hand = columns 7-9
I would like to find the distances between the positions 'head' and 'left hand' for each cell for each element in the columns. I have the following code:
This code works for one cell in a cell array.
How do I need to write this code if I want to apply it to every cell in the cell array and save the output in a new cell array called 'distances_head_lefthand'?
Thank you!

DGM on 13 Feb 2022
How about something like this?
f = @(x) sqrt(((x(:,4)-x(:,1)).^2) ...
+ ((x(:,5)-x(:,2)).^2) ...
+ ((x(:,6)-x(:,3)).^2));
distances_head_lefthand = 1×3 cell array
{20×1 double} {20×1 double} {20×1 double}
lil brain on 13 Feb 2022
This works well thanks!