How to create this function?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I've read how to build a function. But I'm still struggling with this... I've created a code to read c3d-files into Matlab. The output is a 5x5 struct (the 5 rows represent the subjects, and the 5 columns represent the measurements). This is my code I want to create a function for:
aantal_proefpersonen = length(dir('data_stair_rise'))-2;
for welke_pp=1:aantal_proefpersonen %for the 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 each c3dfile
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
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
0 Commenti
Risposta accettata
Geoff Hayes
il 26 Dic 2014
Sam - just go into the MATLAB editor and create a new file whose first line is
function readc3dFiles
and copy and paste your above code as the body to your function. Then save this file (the default name should be readc3dFiles.m) and call it from the command line by typing
readc3dFiles
in the command window. If you need to pass any parameters to your function or return any output parameters, you can adjust your function signature.
2 Commenti
Geoff Hayes
il 27 Dic 2014
Sam - just pass the folder name as an input parameter to your function so that your code will just use the one function to read the data from both folders. Or, pass a cell array of the two folder names and then have your code loop over the elements in your array.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!