how to create empty string arrays and then populate them through arrayName(indexNumber) syntax

Antworten (3)

Declare an empty string array in this manner:
C=string.empty;
C(1)='hello';
C(2) = 'goodbye';
c{1} = 'hello';

2 Kommentare

This is a workaround, but it actually creates a cell array of strings.
"This is a workaround, but it actually creates a cell array of strings. "
At the time this question was posed (and answered) the string class did not exist (it was only introduced in R2016b). Each element of a character array stores only one character, so (until the string class was introduced) the only way to store multiple characters using a scalar index (as the question poses) is to use a cell array. From that persepctive it is not a "workaround", it is the correct solution for versions of MATLAB before R2016b.

Melden Sie sich an, um zu kommentieren.

You can initialise an empty string array with:
s = strings(0)
to which the response is:
s =
0×0 empty string array

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 20 Feb. 2014

Beantwortet:

am 9 Jun. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by