Opening .sto File in MATLAB

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Alison Rogozinski
Posts: 14
Joined: Tue Jun 07, 2016 7:44 am

Opening .sto File in MATLAB

Post by Alison Rogozinski » Wed Jun 22, 2016 7:47 am

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.

User avatar
John Rogers
Posts: 45
Joined: Fri Feb 24, 2012 11:47 am

Re: Opening .sto File in MATLAB

Post by John Rogers » Wed Jun 22, 2016 12:17 pm

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)

User avatar
Aaron Godfrey
Posts: 55
Joined: Tue Feb 16, 2016 12:34 pm

Re: Opening .sto File in MATLAB

Post by Aaron Godfrey » Thu Jun 30, 2016 5:50 am

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.

POST REPLY