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?
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 Exchange에서 Loops 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