how to split strings equally with a rest

조회 수: 10 (최근 30일)
Elie Elias
Elie Elias 2018년 10월 14일
편집: madhan ravi 2018년 10월 14일
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일
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
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개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by