Page 1 of 1

Opening .sto File in MATLAB

Posted: Wed Jun 22, 2016 7:47 am
by alisonrogo
Hello everyone,
I am currently working on a project and my mentor wants me to open an .sto file in MATLAB. I have labeled each .sto file with a variable but cannot get one column to extract out. Can anyone help me with my issue. I would like to graph the one column with another array. Your help will be greatly appreciated.

Re: Opening .sto File in MATLAB

Posted: Wed Jun 22, 2016 12:17 pm
by resodad
Hi Alison,
Matlab importdata() works for text files.

Try this code; save it as an .m file.
Change the file name, and
change "muscleVarname" (the header name) to match your data.
Then run it.
It extracts one column, saves it as a .mat file, and plots it.

Regards,
John


%% Import and Save OpenSim Data
% convert to .mat
%
%
% John Rogers
%
%
% * v1:

%%
clear; clc; close all

%%

fileName = 'subject01_running_CMC_Actuation_force.sto'

varData = importdata(fileName)
dataSize = size(varData.data);
timeKQ = varData.data(:, 1);% time is the first column.
%%
for headerNum = 1:dataSize(2)
muscleVarname = 'glut_med1_r'
if strcmp(varData.colheaders{headerNum},muscleVarname);
myIndex = headerNum;
myForce = varData.data(:,myIndex);
savefile = [fileName,'.mat'];
save(savefile, 'timeKQ', 'myForce');
end
end

%%
plot(timeKQ,myForce)

Re: Opening .sto File in MATLAB

Posted: Thu Jun 30, 2016 5:50 am
by godfreap
Yeah, use importdata, like John mentioned. I'd add though that sometimes it has a problem with .sto and .mot files for some reason - sometimes it'll only load the header, for no particular reason. If that happens, just open the file in excel and save it as an xlsx file. Then you can use importdata with no problem, or xlsread if you don't like structure outputs.