Azzera filtri
Azzera filtri

Matlab: array of strings

1 visualizzazione (ultimi 30 giorni)
marianoc84
marianoc84 il 17 Ott 2011
Inside a Matlab function I need something like (as you can imagine in real life it should be represented as a for loop):
var(1) = 'First string';
var(2) = 'Second string';
...
var(i) = 'i-th string';
Alas, I can't do this cause var(1) should contain just a character (not an entire string) and I get:
??? Subscripted assignment dimension mismatch.
I've searching on the web, but I can't find a good solution, any ideas?
  1 Commento
Jan
Jan il 17 Ott 2011
Then you search procedure was inefficient. The first 3 pages found by asking Google for "Matlab list of strings" contain the necessary information, that this is called "cell string" in Matlab. "docsearch strings" find good explanations in the local docs of Matlab.

Accedi per commentare.

Risposte (1)

Fangjun Jiang
Fangjun Jiang il 17 Ott 2011
Use cell array of strings:
var{1} = 'First string';
var{2} = 'Second string';
  3 Commenti
Sean de Wolski
Sean de Wolski il 17 Ott 2011
var{2} = 'Second string';
var{1} = 'First string';
Switch 'em to dynamically preallocate!
Fangjun Jiang
Fangjun Jiang il 17 Ott 2011
@Sean, that's a neat trick!

Accedi per commentare.

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by