i want to split a string in equal parts like in this example:input='abcdefghijk' output='abc def ghi jk'

 채택된 답변

madhan ravi
madhan ravi 2018년 10월 14일
편집: madhan ravi 2018년 10월 14일

0 개 추천

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

madhan ravi
madhan ravi 2018년 10월 14일
편집: madhan ravi 2018년 10월 14일
Make sure to accept and also give a vote if it was useful the answer if it helped
Image Analyst
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.
madhan ravi
madhan ravi 2018년 10월 14일
Thank you @sir Image Analyst rectified :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2018년 10월 14일

편집:

2018년 10월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by