Convert .mat/csv file to c3d or trc

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Reuben Addison
Posts: 7
Joined: Mon Aug 20, 2018 11:18 am

Convert .mat/csv file to c3d or trc

Post by Reuben Addison » Tue Apr 14, 2020 1:19 pm

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.

Tags:

User avatar
Mohammadreza Rezaie
Posts: 407
Joined: Fri Nov 24, 2017 12:48 am

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

Post by Mohammadreza Rezaie » Tue Apr 14, 2020 2:35 pm

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

User avatar
Reuben Addison
Posts: 7
Joined: Mon Aug 20, 2018 11:18 am

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

Post by Reuben Addison » Tue Apr 14, 2020 6:41 pm

Thank you. My Btk is crushing my Matlab so I will use the second alternative

POST REPLY