Opening .sto files in MATLAB
- Misha Patel
- Posts: 17
- Joined: Mon Jun 05, 2017 2:07 am
Opening .sto files in MATLAB
Hi,
I am trying to do a point kinematics analysis to obtain the vectors of velocity of a knee model while it walks.
I have run the analysis and want to see the '.sto' file... In the 'getting started with analyses section of the OpenSim documentation- it says that it is possible to open the file in MATLAB? Can I have some guidance on this please.
Also, is this the correct way to go about getting vectors of velocity?
Thank you.
I am trying to do a point kinematics analysis to obtain the vectors of velocity of a knee model while it walks.
I have run the analysis and want to see the '.sto' file... In the 'getting started with analyses section of the OpenSim documentation- it says that it is possible to open the file in MATLAB? Can I have some guidance on this please.
Also, is this the correct way to go about getting vectors of velocity?
Thank you.
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Opening .sto files in MATLAB
One way is to implement a .sto importer:
Yes PointKinematics and BodyKinematics are the correct way to get positions, velocities and accelerations of points and bodies.
Code: Select all
function q = readMotionFile(fname)
% Purpose: This function reads a file in the format of a SIMM motion file
% and returns a data structure
%
% Input: fname is the name of the ascii datafile to be read
% ('character array')
%
% Output: q returns a structure with the following format:
% q.labels = array of column labels
% q.data = matrix of data
% q.nr = number of matrix rows
% q.nc = number of matrix columns
%
% ASA 12/03
% Modified by Eran Guendelman 09/06
% Open ascii data file for reading.
fid = fopen(fname, 'r');
if fid == -1
error(['unable to open ', fname])
end
% Process the file header;
% store # data rows, # data columns.
q.nr = 0; % Added to ensure that the q structures from reading a motion file
q.nc = 0; % are always the same, even if nr and nc are different orders in file.
nextline = fgetl(fid);
while ~strncmpi(nextline, 'endheader', length('endheader'))
if strncmpi(nextline, 'datacolumns', length('datacolumns'))
q.nc = str2num(nextline(findstr(nextline, ' ')+1 : length(nextline)));
elseif strncmpi(nextline, 'datarows', length('datarows'))
q.nr = str2num(nextline(findstr(nextline, ' ')+1 : length(nextline)));
elseif strncmpi(nextline, 'nColumns', length('nColumns'))
q.nc = str2num(nextline(findstr(nextline, '=')+1 : length(nextline)));
elseif strncmpi(nextline, 'nRows', length('nRows'))
q.nr = str2num(nextline(findstr(nextline, '=')+1 : length(nextline)));
end
nextline = fgetl(fid);
end
% Process the column labels.
nextline = fgetl(fid);
if (all(isspace(nextline))) % Blank line, so the next one must be the one containing the column labels
nextline = fgetl(fid);
end
q.labels = cell(1, q.nc);
for j = 1:q.nc
[q.labels{j}, nextline] = strtok(nextline);
end
% Process the data.
% Note: transpose is needed since fscanf fills columns before rows.
q.data = fscanf(fid, '%f', [q.nc, q.nr])';
fclose(fid);
return;
- Misha Patel
- Posts: 17
- Joined: Mon Jun 05, 2017 2:07 am
Re: Opening .sto files in MATLAB
Thanks
Can I run that code in MATLAB?
Can I run that code in MATLAB?
Last edited by Misha Patel on Thu Jul 20, 2017 12:49 am, edited 3 times in total.
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Opening .sto files in MATLAB
This is a Matlab function. Just copy in a separate file with same name (readMotionFile.m) and call the function by providing the absolute path to your .sto file (e.g. q = readMotionFile("my.sto")). Do not change the arguments to fopen!
- Misha Patel
- Posts: 17
- Joined: Mon Jun 05, 2017 2:07 am
Re: Opening .sto files in MATLAB
oh thanks. I have it now. As expected, 'q' appears in my workspace. What do the different 'states' mean in the data section? currently only the time is giving me data. the rest of the columns give me 0's... is this to do with how I've carried out the point kinematics trial?
- shayan moradkhani
- Posts: 41
- Joined: Fri May 05, 2017 5:12 pm
Re: Opening .sto files in MATLAB
hi,
i have carried out a pointkinematics and a part of my results are attached. my concern is time steps. is there any way to get times with a certain time step in .mot or .sto files. what i mean is, the time is not uniformly stated here. i am trying to have time recordings like from 0, 0.1, 0.2,... .
it would be good a if could find a way to do that.
regards
Shayan
i have carried out a pointkinematics and a part of my results are attached. my concern is time steps. is there any way to get times with a certain time step in .mot or .sto files. what i mean is, the time is not uniformly stated here. i am trying to have time recordings like from 0, 0.1, 0.2,... .
it would be good a if could find a way to do that.
regards
Shayan
- Attachments
-
- Capture.PNG (14.84 KiB) Viewed 681 times
- Thomas Uchida
- Posts: 1792
- Joined: Wed May 16, 2012 11:40 am
Re: Opening .sto files in MATLAB
You can resample the data in MATLAB or Python using an appropriate interpolation strategy.is there any way to get times with a certain time step in .mot or .sto files.
- Misha Patel
- Posts: 17
- Joined: Mon Jun 05, 2017 2:07 am
Re: Opening .sto files in MATLAB
with respect to the data that has been processed using that MATLAB code, do the labels 'state_01', 'state_02' and 'state_03' refer to x,y,z coordinates of the velocity, acceleration and position?
- Thomas Uchida
- Posts: 1792
- Joined: Wed May 16, 2012 11:40 am
Re: Opening .sto files in MATLAB
Yes.do the labels 'state_01', 'state_02' and 'state_03' refer to x,y,z coordinates of the velocity, acceleration and position?