How to convert string or chars to string arrays withing for loop?
Show older comments
How could I convert message to string array withing for loop? Each string in array has to be 4 characters long. For example:
message = 'SOMETEXT';
for i = 1:4:length(message)
%some code here
end
Outcome would be:
out = ["SOME", "TEXT"];
Many thanks
Accepted Answer
More Answers (2)
An easy way, with no loop, a bit similar to Stephan's answer:
%demo data:
in = char(randi(double('AZ'), 1, 28)) %random string of 28 characters
out = string(reshape(in, 4, [])')
Element
on 4 Nov 2019
0 votes
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!