Page 1 of 1

Convert .mat/csv file to c3d or trc

Posted: Tue Apr 14, 2020 1:19 pm
by reubebe
How do you convert a .mat or csv file to c3d motion data. I want to import the data into OpenSim for processing. But if I am to get it into just c3d I can do the rest. The data was download from an open source repository.

Re: Convert .mat/csv file to c3d or trc

Posted: Tue Apr 14, 2020 2:35 pm
by kernalnet
Hi,

I would suggest you use the BTK package.
http://biomechanical-toolkit.github.io/ ... ng/Matlab/

If you have a double which contains XYZ of whole markers, first convert it to a struct:

Code: Select all

data = struct;   % create an empty struct
for i = 1:Nmarkers   % number of markers
	data.(lables{i}) = markers(:,[3*i-2 3*i-1 3*i]);   % lables is a cell contains the marker labels
end
Then use BTK for creating a c3d file:

Code: Select all

acq = btkNewAcquisition(Nmarkers, frames ); % number of markers and frames
btkSetFrequency(acq, Rmarkers);  % sampling frequency 
for i = 1:Nmarkers
    btkSetPointLabel(acq, i, lables{i});
    btkSetPoint(acq, i, data.(lables{i})); 
end
btkWriteAcquisition(acq, 'NEW.c3d');
You can set the analog and force data to your file too.

But isn't it more convenient to generate OpenSim required files from your CSV or mat data without converting them to a c3d file?
You have all, just write them as an ASCII (trc or mot) or use OpenSim functions instead.

Hope this helps.

Regards

Re: Convert .mat/csv file to c3d or trc

Posted: Tue Apr 14, 2020 6:41 pm
by reubebe
Thank you. My Btk is crushing my Matlab so I will use the second alternative