How to create this function?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sam
am 26 Dez. 2014
Kommentiert: Geoff Hayes
am 27 Dez. 2014
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 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 26 Dez. 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 Kommentare
Geoff Hayes
am 27 Dez. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!