One-dimensional array of variable length

21 visualizaciones (últimos 30 días)
John
John el 12 de Abr. de 2011
I need to create a one-dimensional string array of variable length that I can add elements to as needed. I don't know how long it will need to be, as that will be determined by the rest of the program I'm writing, so ideally it will begin with no elements and I can then add as my program loops over other data.
Is there any easy way to do this? Let me know, thanks!
- John

Respuestas (3)

Laura Proctor
Laura Proctor el 12 de Abr. de 2011
Any variable can change length throughout the code. You can run each line below and see what it does to the variable s1.
s1 = 'Peter'
s1 = [ s1 ' Parker']
s1 = 'Spider-man'

bym
bym el 12 de Abr. de 2011
str = []
str = [str,newdata1]
str = [str,newdata2]

Andrei Bobrov
Andrei Bobrov el 13 de Abr. de 2011
better use of cell array
strcll = [];
for j = ...
...
result(j)
...
strcll = [ strcll; {result(j)}];
end

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by