The question is:
Write a script which first defines a cell array of directory names and then uses the command mkdir in a loop to create these directories.
I'm aware that mkdir makes a new directory, I just don't know how to firstly define a cell array of directory names and then use a loop, which I assume is a for loop.

 採用された回答

James Tursa
James Tursa 2020 年 12 月 14 日
編集済み: James Tursa 2020 年 12 月 14 日

0 投票

A cell array uses the curly braces. E.g.,
MyNames = {'ThisName','ThatName','OtherName'};
The number of elements is simply numel(MyNames).
Each element is addressed using the curly braces also. E.g., MyNames{1}, MyNames{2}, etc.

4 件のコメント

Liz
Liz 2020 年 12 月 14 日
Okay, how do i then use a loop to create the directories?
James Tursa
James Tursa 2020 年 12 月 14 日
Just use numel(MyNames) as the indexing limit. E.g.,
for k=1:numel(MyNames)
% do whatever you need to do here
end
Liz
Liz 2020 年 12 月 14 日
I need to create the directories using mkdir. I feel as though I am overcomplicating this!
James Tursa
James Tursa 2020 年 12 月 14 日
If the index variable is k like I have above, then MyNames{k} is the name. Use that in your loop.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2020b

質問済み:

Liz
2020 年 12 月 14 日

コメント済み:

2020 年 12 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by