Trying to access individual columns in a map container that has 41 markers, each with an XYZ point.

1 vue (au cours des 30 derniers jours)
Hello! I am new to matlab and newer to using map contianers. My project is using data collected from a motion caputre system to find joint angles. Right now I am trying to figure out how to access indivdual columns within the Names of my container. Currently I can call on it based off the name, but it returns the XYZ points when I just want to access X Y or Z at a time. Currently commented out is the graphing of the walking movement. Any tips would be appretiated. Thank you! (I also attached the data)
My Code:
clear
clc
[NUM,TXT,RAW]=xlsread('WalkData');
time=NUM(:,2);
Columns=numel(NUM(1,:));
PartIndex=[];
Parts=[];
ABC=containers.Map();
Points=[];
figure;
markers=3:3:length(NUM(1,3:end));
% for k = 1:length(time)
% plot3(NUM(k,markers),NUM(k,markers+2),NUM(k,markers+1),'o');
% view(115,10)
% axis([0 2000 -500 2000 0 2000])
% xlabel('X');
% xticks([0 500 1000 1500 2000])
% ylabel('Z');
% yticks([-500 0 500 1000 1500 2000])
% zlabel('Y');
% zticks([0 500 1000 1500 2000])
% pause(0.01)
% end
for i = 3:3:Columns %go through all collums minus intial time and frame
X=NUM(:,i); %get all X values of position
Y=NUM(:,i+1); %get all Y values of position
Z=NUM(:,i+2); %get all Z values of position
Part=TXT(1,i); %get all parts in order of sheet assuming label is above x axis
Parts=[Parts, Part];
PartIndex= [PartIndex, [Part, [X Y Z]]];
Points= [Points, [X Y Z]]; %Array of all X Y and Z values in every row
%want to split ABC up by each occurance of a new body part, pr by
%groups of 3, but assign to the relating boday part
end
ABC = containers.Map(PartIndex(1:2:end), PartIndex(2:2:end));
%ABC('R.ASIS') how to access data based on part
Names=keys(ABC);
XYZ=values(ABC);
  2 commentaires
maura belcher
maura belcher le 13 Juil 2022
Thank you very much! This simplified it a lot for me and helped me understand.
William Rose
William Rose le 14 Juil 2022
@maura belcher, You are welcome. The script that I posted as a comment shows how to quickly populate the map container with 41 keys and 41 values* from the Excel file. I probably should have done that first.
*Each "value" is a 151x3 array.

Connectez-vous pour commenter.

Réponse acceptée

William Rose
William Rose le 13 Juil 2022
I have never heard of or worked with map containers, but I can see they could be useful in this situaiton if we can figure out how to set it up.
The data is sampled at 60 Hz for 2.5 seconds. The subject appears to be walking on a treadmill. The global coordinate system appears to be oriented with +X=forward, +Y=up, and +Z=to the subject's right.
Your map container will have 41 keys, which are the names of 41 markers. Each map value will be an array of 151 x 3 doubles, which are the x,y,z coordinates of each marker, sampled at 60 Hz for 2.5 seconds. Let's try a simplified version:
time=[0:150]'/60; %60 Hz for 2.5 seconds
%X,Y,Z in mm. +X=forward, +Y=up, +Z=right
rasis=[600+30*sin(2*pi*time/0.6), 1070-20*cos(2*pi*time/0.6), 140-30*sin(2*pi*time/1.2)];
%LASIS is 2 cm lower than RASIS in this example
lasis=[600+30*sin(2*pi*time/0.6), 1050-20*cos(2*pi*time/0.6), -140-30*sin(2*pi*time/1.2)];
vsacrum=[440+30*sin(2*pi*time/0.6), 1060-20*cos(2*pi*time/0.6), -30*sin(2*pi*time/1.2)];
k={'R.ASIS','L.ASIS','V.SACRUM'};
v={rasis,lasis,vsacrum};
ABC=containers.Map(k,v);
% Define pelvis origin at each instant as midpoint of RASIS and LASIS:
pelv.orig=(ABC('R.ASIS')+ABC('L.ASIS'))/2;
fprintf('Rows 1-3 of pelvis origin\n');
Rows 1-3 of pelvis origin
disp(pelv.orig(1:3,:)) %display rows 1-3 of pelvis origin vector
1.0e+03 * 0.6000 1.0400 0 0.6052 1.0403 -0.0026 0.6103 1.0412 -0.0052
% Compute a vector at each instant that points from LASIS to RASIS
pelv.n=(ABC('R.ASIS')-ABC('L.ASIS'));
fprintf('Rows 1-3 of vector from LASIS to RASIS\n');
Rows 1-3 of vector from LASIS to RASIS
disp(pelv.n(1:3,:)) %display rows 1-3 of pelvis vector n
0 20 280 0 20 280 0 20 280
% I don't know a way to directly access one element or row or column of ABC('R.ASIS').
% ABC('R.ASIS')(1,1) is an error. ABC('R.ASIS'(1,1)) is an error.
% You can assign ABC('R.ASIS') to a variable and then access its parts in the
% usual way, but this defeats some of the supposed advantages of map containers.
asisR=ABC('R.ASIS'); asisL=ABC('L.ASIS'); sacrum=ABC('V.SACRUM');
figure;
subplot(3,1,1)
plot(time,asisL(:,1),'-r.',time,asisR(:,1),'-g.',time,sacrum(:,1),'-b.')
xlabel('Time (s)'); ylabel('X'); grid on;
legend('L.ASIS','R.ASIS','Sacrum'); title('+X=Forward')
subplot(3,1,2)
plot(time,asisL(:,2),'-r.',time,asisR(:,2),'-g.',time,sacrum(:,2),'-b.')
xlabel('Time (s)'); ylabel('Y'); grid on;
legend('L.ASIS','R.ASIS','Sacrum'); title('+Y=Up')
subplot(3,1,3)
plot(time,asisL(:,3),'-r.',time,asisR(:,3),'-g.',time,sacrum(:,3),'-b.')
xlabel('Time (s)'); ylabel('Z'); grid on;
legend('L.ASIS','R.ASIS','Sacrum'); title('+Z=Right')
I realize I did not read in the values form your Exel spreadsheet. But I did demonstrate how to set up a map container with similar data. I showed how to access the data using the map keys (marker names), and do calcualtions with the data, and plot the data.
Try it. Good luck.
  1 commentaire
William Rose
William Rose le 14 Juil 2022
Here is a script that reads the data from your Excel file, puts it in a map container object, and does some kinematic calculations using the data: compute pelvic width, compute unit vectors for pelvis anatomical coordinate system, and estimate locations of hip joint centers at each instant. Results are displayed graphically and on console.
You can use the approach demonstrated here for the pelvis to compute the unit vectors for other segments. Three unit vectors for a segment make a 3x3 rotation matrix for the segment. Once you have the 3x3 rotation matrix for the proximal and distal segments of a joint, you can compute the rotation of the distal segment relative to the proximal segment. Then you can compute the joint angles, as Euler angles (e.g. Grood & SUntay), or as helical axis and angle.
Good luck with your project.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Polar Plots dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by