Skip to main content

storageToDoubleMatrix.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function extracts the data of the OpenSim Storage object to a 2D
% MATLAB array. The organization is column major. I.E. output(0,:) is the
% first column of the Storage (not including the time column)
%
% (Storage) -> (2D Array of double)
% Extracts 2D double Array from Storage object


function output = storageToDoubleMatrix(storage)
import org.opensim.modeling.ArrayDouble

if(class(storage) ~= "org.opensim.modeling.Storage")
storage = org.opensim.modeling.Storage(storage);
end

nCol = storage.getColumnLabels().size()-1;
nRow = storage.getSize();

output = zeros(nCol, nRow);
col = ArrayDouble();
for i=1:nCol
storage.getDataColumn(i-1, col);
for j=1:col.getSize()
output(i, j) = col.getitem(j-1);
end
end
end