divide a string every 15 characters

2 views (last 30 days)
I want to divide this string into 5 strings long 15 characters
A = ["+6.64430238e+00+1.14987825e-02-4.68099585e-06+9.62334222e-10-8.24360065e-14"]; %from this
B = ["+6.64430238e+00" "+1.14987825e-02" "-4.68099585e-06" "+9.62334222e-10" "-8.24360065e-14"]; %to this

Accepted Answer

Star Strider
Star Strider on 7 May 2022
Try this —
A = ["+6.64430238e+00+1.14987825e-02-4.68099585e-06+9.62334222e-10-8.24360065e-14"];
B = string(reshape(char(A),15,[])')'
B = 1×5 string array
"+6.64430238e+00" "+1.14987825e-02" "-4.68099585e-06" "+9.62334222e-10" "-8.24360065e-14"
.
  4 Comments
Star Strider
Star Strider on 7 May 2022
I did not experiment with string methods. I found an approach that worked, and went with it.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by