Info
This question is closed. Reopen it to edit or answer.
How to change my code to read a second datafile?
1 view (last 30 days)
Show older comments
I've got a datafile called 'data_stair_rise'. This datafile contains measurements ( being c3dfiles ) for 5 subjects. I've created a code to read these c3dfiles. I also got a second datafile called 'data_sts'. Is it possible to not simple 'copy-paste' my code and switch 'data_stair_rise' by 'data_sts', but to load data_sts by adjusting my code?
This is my code:
aantal_proefpersonen = length(dir('data_stair_rise'))-2;
for welke_pp=1:aantal_proefpersonen %for 5 subjects
myFolder =sprintf('data_stair_rise/pp%c',num2str(welke_pp));
filePattern = fullfile(myFolder,'*.c3d');
c3dFiles = dir(filePattern);
for i_files=1:length(c3dFiles); %for all c3dfiles for each subject
baseFileName = c3dFiles(i_files).name;
fullFileName = fullfile(myFolder, baseFileName);
[VideoSignals,VideoSignals_headers,AnalogSignals,AnalogSignals_headers,AnalogFrameRate,VideoFrameRate] = read_c3d_file(fullFileName); %function to read the c3dfiles
data_stair_rise(welke_pp, i_files).VideoSignals = VideoSignals; % created a struct to store the data
data_stair_rise(welke_pp, i_files).VideoSignals_headers = VideoSignals_headers;
data_stair_rise(welke_pp, i_files).AnalogSignals = AnalogSignals;
data_stair_rise(welke_pp, i_files).AnalogSignals_headers = AnalogSignals_headers;
data_stair_rise(welke_pp, i_files).AnalogFrameRate = AnalogFrameRate;
data_stair_rise(welke_pp, i_files).VideoFrameRate = VideoFrameRate;
end
end
6 Comments
dpb
on 26 Dec 2014
Same as I said originally except hardcode those filenames into the top-level routine and then call the generic one with those names in a loop.
Or, use the dir solution and get
d=dir('data_*.*');
and loop thru it. If there are ones that aren't wanted, skip 'em or revise the naming scheme to have a better pattern-matching facility.
There are as many ways as people to suggest them...
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!