Cell Arrays and loops

1 visualización (últimos 30 días)
Liz
Liz el 14 de Dic. de 2020
Comentada: James Tursa el 14 de Dic. de 2020
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.

Respuesta aceptada

James Tursa
James Tursa el 14 de Dic. de 2020
Editada: James Tursa el 14 de Dic. de 2020
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 comentarios
Liz
Liz el 14 de Dic. de 2020
I need to create the directories using mkdir. I feel as though I am overcomplicating this!
James Tursa
James Tursa el 14 de Dic. de 2020
If the index variable is k like I have above, then MyNames{k} is the name. Use that in your loop.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by