How do I make multiple folders with specific names?

7 ビュー (過去 30 日間)
Leonore Unknown
Leonore Unknown 2015 年 2 月 16 日
回答済み: MD SHAHNAWAZ RAZA 2018 年 4 月 7 日
I am a real beginner here, so this might be a very stupid question, but can someone explain to me who I can make multiple folders at once? I created a cell array with all the names, now I want the folders to have the same name so I can put my data into it ;)
So I have my cell array with the names I need to have:
connames = {'remembered', 'forgotten', 'remembered-forgotten', 'reforgotten-remembered', 'weak', 'strong', 'weak-strong', 'strong-weak', 'strong-forgotten', 'weak-forgotten' }
And then I want directories containing these names:
clear condir; condir = fullfile(dirs.root,'modelcontrasts',connames);
if ~exist(condir,'dir'); mkdir (condir); end
It however doesn't work like this. What should I do? And why doesn't this work?

採用された回答

Stephen23
Stephen23 2015 年 2 月 16 日
編集済み: Stephen23 2015 年 2 月 16 日
You will have to do this in a loop, something a bit like this:
for k = 1:numel(connames)
condir = fullfile(dirs.root,'modelcontrasts',connames{k});
if 2~=exist(condir,'dir');
mkdir(condir);
end
... other code here
end
Note the special indexing using curly braces for extracting the string filename out of the cell array connames.
Note how I also changed the exist call to match the documentation: exist does not return a boolean logical, but a numeric values depending on what kind of thing it has tested the existence of (directories are 2).
  1 件のコメント
Leonore Unknown
Leonore Unknown 2015 年 2 月 16 日
Thank you very much! so fast :)

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

その他の回答 (1 件)

MD SHAHNAWAZ RAZA
MD SHAHNAWAZ RAZA 2018 年 4 月 7 日
Thank you so much. This code is working fine.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by