What is this code doing?

1 Ansicht (letzte 30 Tage)
Emilia Simonian
Emilia Simonian am 22 Okt. 2020
Kommentiert: Walter Roberson am 23 Okt. 2020
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
  1 Kommentar
Walter Roberson
Walter Roberson am 23 Okt. 2020
The if 0 part is never true, so the code would not do anything.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sindar
Sindar am 23 Okt. 2020
Bearbeitet: Sindar am 23 Okt. 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Search Path 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!

Translated by