How to create a string array with long strings that continue to a new line?
Show older comments
I ran into curious behavior with Matlab R2020b, when I tried to manually create a string array with really long strings that continue to a new line.
In the below examples I have shortened the strings for the sake of readability.
I was surprised that the following input does not concatenate the double "aa"s and "cc"s into individual strings "aaaa" and "cccc".
["aa" ...
"aa", "bbbb", "cc" ...
"cc"]
Instead you get:
ans =
1×5 string array
"aa" "aa" "bbbb" "cc" "cc"
I also tried the following, which results in to a string instead of string array:
['aa' ...
'aa', 'bbbb', 'cc' ...
'cc']
ans =
'aaaabbbbcccc'
Is there a nice way to get what I want, i.e:
1×5 string array
"aaaa" "bbbb" "cccc"
Currently I'm building the string array by adding a new string in separate statements, which is not very elegant.
Accepted Answer
More Answers (1)
Fangjun Jiang
on 8 Apr 2021
Edited: Fangjun Jiang
on 8 Apr 2021
s=["aa"+ ...
"aa", "bb"+ ...
"bb"]
s =
1×2 string array
"aaaa" "bbbb"
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!