How can I save values to an array using a for loop
1 次查看(过去 30 天)
显示 更早的评论
I am trying to create an array or variable that stores filenames for later access. I have tried doing this with a for loop but am forgetting something or doing it wrong. My goal is something similar to:
folderName = [dir([read_dr '\some_folder'])]; %This works
for g = 1:length(folderName)
fileNames = folderName(g).name;
end
disp(fileNames) % Will only show the last value
This will store the value but will only save the last one.
I have also tried:
folderName = [dir([read_dr '\some_folder'])]; %This works
fileNames = {};
for g = 1:length(folderName)
fileNames(g) = folderName(g).name;
end
Which will give the error:
Conversion to cell from char is not possible.
Any help is greatly appreciated!
0 个评论
采纳的回答
Davide Masiello
2022-10-11
编辑:Davide Masiello
2022-10-11
I'd try this
folderName = [dir([read_dr '\some_folder'])]; %This works
fileNames = {};
for g = 1:length(folderName)
fileNames{g} = folderName(g).name;
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!