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!