Hi,
I would like to convert a large structure array of strings into a string
array in a nicely vectorized way.
for example:
octave:15> a={"eins", "zwei", "drei"};
should be converted into
ans =
eins
zwei
drei
=================================================
My first attempt was:
octave:16> a{:}
ans =
(,
[1] = eins
[2] = zwei
[3] = drei
,)
Very nice: this generates a list of strings.
octave:17> [a{:}]
ans = einszweidrei
Here, the elements of the list are concatenated in the wrong way. :-(
=================================================
The cat function can concatenate correctly:
octave:69> cat(1, a{:})
ans =
eins
zwei
drei
However, it is incredibly slow for larger arrays and it cannot handle
strings of different length.
=================================================
This works, but I suppose it's rather slow for large arrays (also it is
not robust if the strings contains things like "):
octave:28> eval(["[", sprintf("""%s"";", a{:}), "]"])
ans =
eins
zwei
drei