What is this code doing?

1 回表示 (過去 30 日間)
Emilia Simonian
Emilia Simonian 2020 年 10 月 22 日
コメント済み: Walter Roberson 2020 年 10 月 23 日
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 件のコメント
Walter Roberson
Walter Roberson 2020 年 10 月 23 日
The if 0 part is never true, so the code would not do anything.

サインインしてコメントする。

採用された回答

Sindar
Sindar 2020 年 10 月 23 日
編集済み: Sindar 2020 年 10 月 23 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by