How can I save values to an array using a for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Sander Janssen
el 11 de Oct. de 2022
Comentada: Sander Janssen
el 11 de Oct. de 2022
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 comentarios
Respuesta aceptada
Davide Masiello
el 11 de Oct. de 2022
Editada: Davide Masiello
el 11 de Oct. de 2022
I'd try this
folderName = [dir([read_dr '\some_folder'])]; %This works
fileNames = {};
for g = 1:length(folderName)
fileNames{g} = folderName(g).name;
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!