Cell Arrays and loops

1 次查看(过去 30 天)
Liz
Liz 2020-12-14
评论: James Tursa 2020-12-14
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
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by