Effacer les filtres
Effacer les filtres

What is this code doing?

4 vues (au cours des 30 derniers jours)
Emilia Simonian
Emilia Simonian le 22 Oct 2020
Commenté : Walter Roberson le 23 Oct 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 commentaire
Walter Roberson
Walter Roberson le 23 Oct 2020
The if 0 part is never true, so the code would not do anything.

Connectez-vous pour commenter.

Réponse acceptée

Sindar
Sindar le 23 Oct 2020
Modifié(e) : Sindar le 23 Oct 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

Plus de réponses (0)

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by