How to create this function?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Geoff Hayes
2014년 12월 26일
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
Geoff Hayes
2014년 12월 27일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!