How to have function mkdir read a variable?
8 次查看(过去 30 天)
显示 更早的评论
Can you mass produce sub folders in a parent folder using 'mkdir'and a variable? Can't figure out how have mkdir function read a variable.
Say we try to mass produce folders titled the following numbers:
>> x = [222990, 222991, 222992, 222993, 222994, 222995]
mkdir parentFolder x (doesn't work, just produces a single folder titled x)
mkdir parentFolder "x" (doesn't work, same issue)
mkdir parentFolder 'x' (doesn't work, same issue)
mkdir parentFolder [x] (doesn't work, same issue)
mkdir parentFolder (x) (doesn't work, same issue)
mkdir parentFolder ['x'] (doesn't work, same issue)
mkdir parentFolder ["x"] (doesn't work, same issue)
2 个评论
采纳的回答
Alvery
2020-12-15
There is another syntactic form for calling functions.
mkdir newfolder
is the same as
mkdir('newfolder')
Since you want to manipulate the folder name, you need to use the second form of the function call, along with string manipulation. There's a second problem. mkdir, unlike many other matlab functions, does not work in a vectorised form. In other words, a single call to mkdir can only create a single folder. So to make one folder per list item, you will need a for loop. Therefore you want something like this:
for fileNum = x
mkdir('parentFolder', ['prefix_' num2str(fileNum)])
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!