User's Manual
Document MV0319P.N
© Xsens Technologies B.V.
MVN User Manual
139
22.1.2 Import to MATLAB
Import MVNX files using the MATLAB files in the MATLAB Installer of MVN Studio. Below is a copy of
the information stored in “main_mvnx.m”. This file intended simply as an example. The user is expected
to expand upon this for their own use, depending on data they have exported to mvnx.
The example code contains:
main_mvnx.m and load_mvnx.m. The file main_mvnx is detailed below. It calls the function
load_mvnx.m, which is based on the MATLAB function for reading XML files.
Example code to read the file:
main_mvnx.m
tree = load_mvnx(filename);
% read some basic data from the file
mvnxVersion = tree;
fileComments = tree.subject.comment;
%read some basic properties of the subject;
frameRate = tree.subject.frameRate;
suitLabel = tree.subject.label;
originalFilename = tree.subject.originalFilename;
recDate = tree.subject.recDate;
segmentCount = tree.subject.segmentCount;
%retrieve sensor labels
%creates a struct with sensor data
sensorData = tree.subject.sensors.sensor;
%retrieve segment labels
%creates a struct with segment definitions
segmentData = tree.subject.segments.segment;
%retrieve the data frames from the subject
nSamples = length(tree.subject.frames.frame);
%pre allocate
%pre allocate some memory for the position of Segment1
p_Segment1 = zeros(nSamples,3);
%read the data from the structure e.g. segment 1
for i=[1:nSamples]
p_Segment1(i,:)=tree.subject.frames.frame(i).position(1:3);
end
%Plot
plot(p_Segment1)
figure
plot3(p_Segment1(:,1),p_Segment1(:,2),p_Segment1(:,3));