how to split strings equally with a rest
5 ビュー (過去 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!