Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to change my code to read a second datafile?

1 vue (au cours des 30 derniers jours)
Sam
Sam le 26 Déc 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaires
dpb
dpb le 26 Déc 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...
Sam
Sam le 27 Déc 2014
So if this is my code, what should I do?
function read_data_stair_rise
%-2 vanwege twee lege plaatsen bij gebruik van dir()
aantal_proefpersonen = length(dir('data_stair_rise'))-2;
%eerste for-loop voor het totaal aantal proefpersonen (5)
for welke_pp=1:aantal_proefpersonen
myFolder =sprintf('data_stair_rise/pp%c',num2str(welke_pp));
%bepalen van het filepatroon om het later te kunnen inlezen
filePattern = fullfile(myFolder,'*.c3d');
c3dFiles = dir(filePattern);
%tweede for-loop voor het totaal aantal c3dFiles voor elke proefpersoon
for i_testen=1:length(c3dFiles);
%baseFileName gehaald uit 'dir(filePattern)'
baseFileName = c3dFiles(i_testen).name;
%volledige filename 'bouwen' met fullfile() commando
fullFileName = fullfile(myFolder, baseFileName);
%gegeven functie 'read_c3d_file()' voor het inlezen van de data
[VideoSignals,VideoSignals_headers,AnalogSignals,AnalogSignals_headers,AnalogFrameRate,VideoFrameRate] = read_c3d_file(fullFileName);
%het aanmaken van een 5x5 struct voor het bestand data_stair_rise
data_stair_rise(welke_pp, i_testen).VideoSignals = VideoSignals;
data_stair_rise(welke_pp, i_testen).VideoSignals_headers = VideoSignals_headers;
data_stair_rise(welke_pp, i_testen).AnalogSignals = AnalogSignals;
data_stair_rise(welke_pp, i_testen).AnalogSignals_headers = AnalogSignals_headers;
data_stair_rise(welke_pp, i_testen).AnalogFrameRate = AnalogFrameRate;
data_stair_rise(welke_pp, i_testen).VideoFrameRate = VideoFrameRate;
end
end
end

Réponses (0)

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by