You need to use cell-arrays:

names = cell(10,1);
for i=1:10
    names{i} = ['Sample Text ' num2str(i)];
end
Answer from Amro on Stack Overflow
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › data type conversion
string, " " - String array - MATLAB
You can represent text in MATLAB® using string arrays where each element of a string array stores a sequence of characters. The sequences can have different lengths without padding, such as "yes" and "no".
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
Create String Arrays - MATLAB & Simulink
Use array indexing to access the first row of str and all the columns. str = ["Mercury","Gemini","Apollo"; "Skylab","Skylab B","ISS"]; str(1,:) ... Access the second element in the second row of str. ... Assign a new string outside the bounds of str. MATLAB expands the array and fills unallocated elements with missing values.
Discussions

matlab - Create an array of strings - Stack Overflow
Is it possibe to create an array of strings in MATLAB within a for loop? For example, for i=1:10 Names(i)='Sample Text'; end I don't seem to be able to do it this way. More on stackoverflow.com
🌐 stackoverflow.com
Create an array of strings
Create an array of strings. Learn more about string, array More on mathworks.com
🌐 mathworks.com
2
0
October 21, 2017
how can I convert an array in double format to string?
Unable to complete the action because of changes made to the page. Reload the page to see its updated state. ... https://www.mathworks.com/matlabcentral/answers/1447199-how-can-i-convert-an-array-in-double-format-to-string More on mathworks.com
🌐 mathworks.com
1
0
September 5, 2021
Why MATLAB added "strings" when we had 'char arrays'?
The reason why strings exist was explained in the previous comment, a small advice for writing utility functions: Use the argument block and specify the type of the argument to be string. This way the function will accept both string and char array as input, but matlab will automatically convert char arrays to string, so that you dont need to write the function for both types. Like this: arguments arg_name string end Source: https://www.mathworks.com/help/matlab/ref/arguments.html#mw_5e008bc6-54ca-4d65-9e4b-13b1f7c10b2e https://www.mathworks.com/help/matlab/matlab_oop/implicit-class-conversion.html#mw_8f39cca8-faf5-414a-a466-f54b3a764008 More on reddit.com
🌐 r/matlab
19
6
June 1, 2024
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
strings - Create string array with no characters - MATLAB
Beyond the second dimension, strings ignores trailing dimensions with a size of 1. For example, strings([3,1,1,1]) produces a 3-by-1 vector of strings with no characters. Example: sz = [2,3,4] creates a 2-by-3-by-4 array. Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 ... This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
Text in String and Character Arrays - MATLAB & Simulink
str is a 2-by-3 string array. You can find the lengths of the strings with the strlength function. ... String arrays are supported throughout MATLAB and MathWorks® products.
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
Frequently Asked Questions About String Arrays - MATLAB & Simulink
Whether you use square brackets, plus, or strcat, you can specify an arbitrary number of arguments. Append a space character between Hello and World. ... string | strlength | contains | plus | strcat | sprintf | dir | cd | copyfile | load | length | size | isempty ... Run the command by entering it in the MATLAB Command Window.
Find elsewhere
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
Cell Arrays of Character Vectors - MATLAB & Simulink
You can sum over TF to find the number of matches. ... Use TF as logical indices to return the matches in C. If you index using smooth parentheses, then the output is a cell array containing only the matches. ... String arrays are supported throughout MATLAB® and MathWorks® products.
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types
Characters and Strings - MATLAB & Simulink
A typical use is to store short pieces of text as character vectors, such as c = 'Hello World'. A string array is a container for pieces of text. String arrays provide a set of functions for working with text as data. You can create strings using double quotes, such as str = "Greetings friend".
🌐
TutorialsPoint
tutorialspoint.com › matlab › matlab_strings.htm
MATLAB - Strings
Following table provides brief description of the string functions in MATLAB − · The following examples illustrate some of the above-mentioned string functions − · Create a script file and type the following code into it − · A = pi*1000*ones(1,5); sprintf(' %f \n %.2f \n %+.2f \n .2f \n 2.2f \n', A) When you run the file, it displays the following result − · ans = 3141.592654 3141.59 +3141.59 3141.59 000003141.59 · Create a script file and type the following code into it − · �ll array of strings str_array = {'red','blue','green', 'yellow', 'orange'}; % Join strings in cell array into single string str1 = strjoin(str_array, "-") str2 = strjoin(str_array, ",")
🌐
Reddit
reddit.com › r/matlab › why matlab added "strings" when we had 'char arrays'?
r/matlab on Reddit: Why MATLAB added "strings" when we had 'char arrays'?
June 1, 2024 -

I have that the two methods are used in parallel. The built-in functions want the 'char' arguments. Most users just simply use "str" and 'char' randomly. The worst part is that when I write a utility function I must support both. The real pain is checking is one of them is empty.

isempty('') does not yield the same result as isempty("")

This thing just makes me wonder, what's the point in introducing a dedicated stirng type after many many years?

Strings were not a thing before 2016b! Yes, strings were added in 2016, why?

🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
strjoin - Join strings in array - MATLAB
str = strjoin(C) constructs str by linking the elements of C with a space between consecutive elements. C can be a cell array of character vectors or a string array.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 116857-how-to-create-empty-string-arrays-and-then-populate-them-through-arrayname-indexnumber-syntax
how to create empty string arrays and then populate them through arrayName(indexNumber) syntax - MATLAB Answers - MATLAB Central
February 20, 2014 - https://www.mathworks.com/matlabcentral/answers/116857-how-to-create-empty-string-arrays-and-then-populate-them-through-arrayname-indexnumber-syntax#comment_703920 ... 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.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 509085-looping-through-an-array-of-strings
Looping through an array of strings - MATLAB Answers - MATLAB Central
March 4, 2020 - Hello, I have an array of trial names (i.e. trials = {'Standing', 'Walking'}, etc.) and I want to loop through the array to create new variables like so: for trialnum = 1:11; trial = trials(t...