You should call the cell's content via str{1} as follows to make it correct:

for str = {'aaa','bbb'}
  fprintf('%s\n',str{1});
end

Here's a more sophisticated example on printing contents of cell arrays.

Answer from petrichor on Stack Overflow
🌐
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...
Discussions

For loop in string array
For loop in string array. Learn more about for loop MATLAB More on mathworks.com
🌐 mathworks.com
1
0
January 19, 2023
Is it possible to iterate over a cell of strings in order to create new variables?
I have to do the same thing for several sets of strings so I would like to make a for loop if I could. would it be possible for me to iterate through this cell: s = {'PTV','Rec','Blad','Pros',... More on mathworks.com
🌐 mathworks.com
2
0
August 4, 2015
How does one create an array of strings in a loop? In a better way.
How does one create an array of strings in a... Learn more about matlab, strings, splitting strings, strsplit, loop More on mathworks.com
🌐 mathworks.com
1
0
June 7, 2013
Beginner: How do I loop through strings ?
Do not hide an index in the name of a variable, but use an array and an index: ... This is some pseudo-code only, because it is not clear, what the contents of your variables is. ... https://www.mathworks.com/matlabcentral/answers/1829138-beginner-how-do-i-loop-through-strings#comment_2423068 More on mathworks.com
🌐 mathworks.com
1
0
October 17, 2022
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1896985-for-loop-in-string-array
For loop in string array - MATLAB Answers - MATLAB Central
January 19, 2023 - Hello Matlab Community, How can I loop though my string array to get indexes? Here is my code using for loop but it creates blank matix after running a for loop. str = importfile("imageTimeline1....
🌐
MathWorks
mathworks.com › matlabcentral › answers › 344045-loop-through-array-of-strings-in-tic
loop through array of strings in tic - MATLAB Answers - MATLAB Central
June 9, 2017 - Hi, I want to loop through an array of strings in tlc that I retrieve from a MATLAB function. I.e., something like the following: (OBS, this code doesn't work) %assign values = FEVAL("m...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 355407-loop-with-strings-array
Loop with strings array - MATLAB Answers - MATLAB Central
September 6, 2017 - You should not define them in different variables, you should define them into a 3D matrix if the dimensions are same or a cell array if dimensions are different. ... Now A can be easily used to loop or for nay other calculations. Sign in to comment. ... The only similar question I can find that you've asked is this one. You were clearly told to use indexing. I need in any case to obtain as output different variables whose name contains the subscript/index · I'm afraid what you need is to change your way of thinking and adapt to the way matlab (and many other languages) work.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 232385-is-it-possible-to-iterate-over-a-cell-of-strings-in-order-to-create-new-variables
Is it possible to iterate over a cell of strings in order to create new variables? - MATLAB Answers - MATLAB Central
August 4, 2015 - I have to do the same thing for several sets of strings so I would like to make a for loop if I could. would it be possible for me to iterate through this cell: s = {'PTV','Rec','Blad','Pros',...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 78372-how-does-one-create-an-array-of-strings-in-a-loop-in-a-better-way
How does one create an array of strings in a loop? In a better way. - MATLAB Answers - MATLAB Central
June 7, 2013 - So I have an array of characters, separated by whitespaces, and obviously matlab recognizes whitespaces as a character too. I wanted to separate the words into strings and put them into one array s...
Find elsewhere
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1829138-beginner-how-do-i-loop-through-strings
Beginner: How do I loop through strings ? - MATLAB Answers - MATLAB Central
October 17, 2022 - Do not hide an index in the name of a variable, but use an array and an index: ... This is some pseudo-code only, because it is not clear, what the contents of your variables is. ... https://www.mathworks.com/matlabcentral/answers/1829138-beginner-how-do-i-loop-through-strings#comment_2423068
🌐
MathWorks
mathworks.com › matlabcentral › answers › 251681-using-strings-as-variable-names-in-a-for-loop
Using strings as variable names in a for loop - MATLAB Answers - MATLAB Central
October 29, 2015 - Open in MATLAB Online · Have you tried stepping line by line using the debugger? You'll notice that in the line · C=zeros(myvar); You're trying to create a vector of zeros with 'myvar', which is a string. You can't call zeros() with a string input. Why don't you just create a cell array which holds K2006, K2007 and their respective values? That way, you can just loop through the cell array.
🌐
Reddit
reddit.com › r/matlab › how to select an individual char from a string?
r/matlab on Reddit: How to select an individual char from a string?
September 20, 2017 -

Hey all, how do I select/index a char from a string?

I've tried doing something like input[i] and iterate over the i, but apparently MATLAB does this indexing differently, and the "i" selects the whole string.

How do I do this? Thanks.

🌐
MathWorks
mathworks.com › matlabcentral › answers › 299668-how-to-store-string-values-from-a-for-loop-into-a-cell-array
How to store string values from a for loop into a cell array? - MATLAB Answers - MATLAB Central
August 15, 2016 - https://www.mathworks.com/matlabcentral/answers/299668-how-to-store-string-values-from-a-for-loop-into-a-cell-array#comment_385442 ... This way you will not need any single quotations and you just have to enter whatever text you want as an input and it will treat it as a string. Sign in to comment. Sign in to answer this question. ... Find the treasures in MATLAB Central and discover how the community can help you! Start Hunting! ... Unable to complete the action because of changes made to the page.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1612895-how-to-use-for-loop-to-string-variable
How to use 'for' loop to string variable ? - MATLAB Answers - MATLAB Central
December 17, 2021 - I have severals mat files. I have defined these files as a string variable in m file. i can execute the files seperately with a loop. 1st mat file: Battery_Power_280.mat 2nd mat file: Battery_Po...