MATLAB: What is this code doing

newtomatlab

if 0,
mfiles={'bh_plot_session','rsbs_prepare_formodel','rsbs_speed_stats_extra','resscn_prepare_formodel','speed_stats_extra'}
savedir = 'C:\TEMP\behav\';
if ~isdir(savedir),mkdir(savedir);end
for i=1:length(mfiles),
src=which([mfiles{i},'.m']);
[x,y,z]=fileparts(src)
dst=[savedir,'\',y,z]
copyfile(src,dst);
end
end

Best Answer

Short version: copy a list of Matlab script/function files from wherever Matlab finds them into a particular directory ('C:\TEMP\behav\')
Long version:
% currently does nothing, since 0 is false
if 0,
% define a set of files
% below, we see that these are expected to be .m files
mfiles={'bh_plot_session','rsbs_prepare_formodel','rsbs_speed_stats_extra','resscn_prepare_formodel','speed_stats_extra'}
% define a directory
savedir = 'C:\TEMP\behav\';
% if that directory doesn't already exist, create it
if ~isdir(savedir),mkdir(savedir);end
% loop over file set
for i=1:length(mfiles),
% get full path of file
src=which([mfiles{i},'.m']);
% extract path (x), name (y) and extension (z) of file
[x,y,z]=fileparts(src)
% define a location to save the file
% specifically, copy it into the above directory, keeping the same filename
dst=[savedir,'\',y,z]
copyfile(src,dst);
end
end