Read c3d-files into Matlab

I have two directories of data: 'data_stair_rise' and 'data_sts'. Each directory contains 5 subfolders: 'pp1', 'pp2', 'pp3', 'pp4' en 'pp5'. Each subfolder contains some '.c3d-files'. (see attachment).
We need to read these files into Matlab. The teacher gave us a function who can read these c3d-files, but we need to create 5x5 struct (5 subjects x 5 measurements). (see attachment).
I don't have ANY idea how to start... Please help.

2 个评论

Can you share the command used to read the c3d file please
@Suad Abu Shaar, @Sam had a function he called "read_c3d_file" but he never attached it. And since it's 9 years later, I doubt he ever will.

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2014-12-24

0 个投票

I don't know what's in the file. In a single .c3d file, how many subjects, and how many measurements are in it?
When you use your teacher's function, what kind of variable does the file get read in to? A single structure? An array of structures? We have no idea, but you should since you and your teacher have the code.

8 个评论

In the single .c3d-file are 6 things: VideoSignals (datapoints), VideoSignal_header, AnalogSignals, AnalogSignals_headers, VideoFramerate, Analogframerate. Each subject has (at least) 4 .c3d-files. So 1 .c3d-file represent 1 single measurement.
We need to create a 5x5struct, so that each cell is a struct which contains the '6 things' of the .c3d-file.
I think we need to start off with creating a path and using command like 'dir' and 'sprintf'... I'm trying to, but I think this is to difficult at the moment. All help is welcome!
If you have questions still after reading the FAQ, come back and ask. http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
This is what I already have:
aantal_proefpersonen = length(dir('data_stair_rise'))-2 %for 5 subjects
for welke_pp=1:aantal_proefpersonen
myFolder =sprintf('data_stair_rise/pp%c',num2str(welke_pp)); %define folder
filePattern = fullfile(myFolder,'*.c3d');
c3dFiles = dir(filePattern); %list c3dfiles
for i_files=1:length(c3dFiles); %for all cd3files in the folder
baseFileName = c3dFiles(i_files).name;
fullFileName = fullfile(myFolder, baseFileName);
[VideoSignals,VideoSignals_headers,AnalogSignals,AnalogSignals_headers,AnalogFrameRate,VideoFrameRate] = read_c3d_file(fullFileName) %function the teacher gave us
end
end
The problem is that the program overwrites everything when going through the for-loops. It also stores everything seperately (see attachment), but I want to stores each c3dfile into a 5x5 struct (as said above, also see attachment above). I hope you understand what I mean and that you can help me. Thanks!
I'm not sure how a 5x5 struct array holds 6 things. But you can just dynamically create indexes and fields, like
for col = 1 : 5
for row = 1 : 5
sa(row, col).field1 = thing1; % Whatever this is.
sa(row, col).field2 = thing2; % Whatever this is.
sa(row, col).field3 = thing3; % Whatever this is.
sa(row, col).field4 = thing4; % Whatever this is.
sa(row, col).field5 = thing5; % Whatever this is.
sa(row, col).field6 = thing6; % Whatever this is.
end
end
You can call the fields whatever you want and somehow read the 6 "things" from your data file before assigning them to the structure array, sa. I don't really know what rows and columns represent but I guess you will. Add a third index to sa if you need to, to represent the four cd3 files for each subject.
Indeed, this creates the 5x5struct that I want (a 5x5 struct and each cell is also a struct containing the 6 datafiles). But the problem is now that each cell (=1x1struct) of the 5x5struct (=sa) is the same...
This is my code:
aantal_proefpersonen = length(dir('data_stair_rise'))-2
for welke_pp=1:aantal_proefpersonen
myFolder =sprintf('data_stair_rise/pp%c',num2str(welke_pp));
filePattern = fullfile(myFolder,'*.c3d');
c3dFiles = dir(filePattern);
for i_files=1:length(c3dFiles);
baseFileName = c3dFiles(i_files).name;
fullFileName = fullfile(myFolder, baseFileName);
[VideoSignals,VideoSignals_headers,AnalogSignals,AnalogSignals_headers,AnalogFrameRate,VideoFrameRate] = read_c3d_file(fullFileName)
for col = 1:length(c3dFiles)
for row = 1:aantal_proefpersonen
sa(row, col).VideoSignals = VideoSignals; % Whatever this is.
sa(row, col).VideoSignals_headers = VideoSignals_headers; % Whatever this is.
sa(row, col).AnalogSignals = AnalogSignals; % Whatever this is.
sa(row, col).AnalogSignals_headers = AnalogSignals_headers; % Whatever this is.
sa(row, col).AnalogFrameRate = AnalogFrameRate; % Whatever this is.
sa(row, col).VideoFrameRate = VideoFrameRate; % Whatever this is.
end
end
end
end
What should I do so that each cell is not the same?
First of all, let's not call it a cell since it's not. That's an entirely different animal One element of a structure array is a structure, not a cell.
In your loop, the values like VideoSignals are not changing. Why not? Well it's because they're always the same since there were assigned before the loop. If you want different ones, then you have to call read_c3d_file() INSIDE THE LOOP, not prior to it. Don't you understand that if you call read_c3d_file() before then those values will be the same no matter how many times you iterate a loop? Why should they change? They won't , unless you update them with a call to read_c3d_file().
Sam
Sam 2014-12-25
编辑:Sam 2014-12-25
Thanks, I understand that. But where exactly should I place 'reac_c3d_file()' to solve the problem? I tried different things, I replaced 'read_c3d_file()' but I still don't get the result I want...
Sam
Sam 2014-12-26
编辑:Sam 2014-12-26
How can I jump back to the first for-loop?

请先登录,再进行评论。

Walter Roberson
Walter Roberson 2023-5-24

0 个投票

see https://www.mathworks.com/matlabcentral/fileexchange/69372-ezc3d
and tools listed at https://www.c3d.org/c3dapps.html

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

提问:

Sam
2014-12-24

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by