Cell Arrays and loops
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Liz
am 14 Dez. 2020
Kommentiert: James Tursa
am 14 Dez. 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.
0 Kommentare
Akzeptierte Antwort
James Tursa
am 14 Dez. 2020
Bearbeitet: James Tursa
am 14 Dez. 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 Kommentare
James Tursa
am 14 Dez. 2020
If the index variable is k like I have above, then MyNames{k} is the name. Use that in your loop.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!