Build a vector of file names with formatting and leading zeros
6 次查看(过去 30 天)
显示 更早的评论
How can I build a vector of file names with format "sprintf('myfile_%02d_%03d.txt', firstInteger, secondInteger)" where "firstInteger" is a 1-2 digit and "secondInteger" is a 2-3 digit are positive integer such that the former has a eading 0 if it were 1 digit and the latter has a leading 0 if it were 2 digits. If I have all "N" integers pairs "firstInteger" and "secondInteger" in the rows of an Nx2 matrix FileNameIntegersMatrix = [firstInteger1 secondInteger1; firstInteger2 secondInteger2, ..., firstIntegerN secondIntegerN], is there a fast and efficient way to build all the files names in a vector with format such as below where each row is a string of the file name with the format shown above.
FileNames = [sprintf('myfile_%02d_%03d.txt', firstInteger1, secondInteger1) ; sprintf('myfile_%02d_%03d.txt', firstInteger2, secondInteger2) , ..., sprintf('myfile_%02d_%03d.txt', firstIntegerN, secondIntegerN)]
0 个评论
采纳的回答
更多回答(1 个)
Sulaymon Eshkabilov
2021-8-4
You can try using strcat() that works quite efficiently, e.g.:
A = 'My_file_'; B='_';
firstInteger1=10; secondInteger1=20;
Filenames = strcat(A, num2str(firstInteger1), B, num2str(secondInteger1))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!