Initializing a char structure for a loop

I am building up a char structure of file paths and names in a large for loop in the form
list=[]
for i =1:n
stuff
file = something
list=char(list,file)
end
My problem is that the first row of list is empty doing it like this. Is there a way to initialize a char array without creating an empty row? I can remove it afterwards but that seems messy.
And in case there is a generally better method of compiling file paths, I'm working within a pipeline that requires me to construct this.
Thanks

 Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Mayo de 2015
list = cell(n, 1);
for i = 1 : n
stuff
list{i} = file;
end
list = char(list);

1 comentario

Jacob Matthews
Jacob Matthews el 8 de Mayo de 2015
Thanks, I've been using list = list(2:end,:) after my loop, so same number of lines, but I imagine memory management is better your way. I was just hoping there was a different method of initialization for the list that wouldn't stack when char'd.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Mayo de 2015

Comentada:

el 8 de Mayo de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by