What is this code doing?

1 visualización (últimos 30 días)
Emilia Simonian
Emilia Simonian el 22 de Oct. de 2020
Comentada: Walter Roberson el 23 de Oct. de 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 comentario
Walter Roberson
Walter Roberson el 23 de Oct. de 2020
The if 0 part is never true, so the code would not do anything.

Iniciar sesión para comentar.

Respuesta aceptada

Sindar
Sindar el 23 de Oct. de 2020
Editada: Sindar el 23 de Oct. de 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

Más respuestas (0)

Categorías

Más información sobre Search Path en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by