how to split strings equally with a rest
10 次查看(过去 30 天)
显示 更早的评论
i want to split a string in equal parts like in this example:input='abcdefghijk' output='abc def ghi jk'
0 个评论
采纳的回答
madhan ravi
2018-10-14
编辑:madhan ravi
2018-10-14
input_string ='abcdefghijk' % don’t use variable name as input because it may contradict with built-in function
ns = numel(input_string);
n = 3;
Output = cellstr(reshape([input_string repmat(' ',1,ceil(ns/n)*n-ns)],n,[])')' % as cell
Output = char(Output) % as char
3 个评论
Image Analyst
2018-10-14
Please, in your answer, correct bad mistakes that the poster made, like calling the variable by the name of a built-in function like input() -- don't let them pass by without pointing them out.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!