I have 26 characters A to Z, I group 4 characters together and separate the following 4 characters by a space which is like this:
abcd efgh ijkl mnop qrst uvwx y
Code ( an approach with vec2mat) -
%// Input
input_str = 'abcdefghijklmnopqrstuvwxyz' %// Input
%// Parameters
group_numel = 4;
num_groups_per_row = 2;
str1 = vec2mat(input_str,group_numel)
str2 = [str1,repmat(' ',size(str1,1),1)]
output_str = vec2mat(str2,(group_numel+1)*num_groups_per_row)
Code run -
>> input_str
input_str =
abcdefghijklmnopqrstuvwxyz
>> output_str
output_str =
abcd efgh
ijkl mnop
qrst uvwx
yz