How do I apply distance formula for 3D coordinate points for all elements in a cell array?
조회 수: 4 (최근 30일)
이전 댓글 표시
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:
distances_head_lefthand = sqrt(((participant_positions{1,1}(:,4)-participant_positions{1,1}(:,1)).^2)+((participant_positions{1,1}(:,5)-participant_positions{1,1}(:,2)).^2)+((participant_positions{1,1}(:,6)-participant_positions{1,1}(:,3)).^2));
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!
댓글 수: 0
채택된 답변
DGM
2022년 2월 13일
How about something like this?
S = load('participants_head_lefthand_righthand_positions.mat');
head_lh_rh_pos = S.participant_head_lefthand_righthand_positions; % good grief
f = @(x) sqrt(((x(:,4)-x(:,1)).^2) ...
+ ((x(:,5)-x(:,2)).^2) ...
+ ((x(:,6)-x(:,3)).^2));
distances_head_lefthand = cellfun(f,head_lh_rh_pos,'uniform',false)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Earth, Ocean, and Atmospheric Sciences에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!