フィルターのクリア

divide a string every 15 characters

1 回表示 (過去 30 日間)
Andrea Somma
Andrea Somma 2022 年 5 月 7 日
コメント済み: Star Strider 2022 年 5 月 7 日
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

採用された回答

Star Strider
Star Strider 2022 年 5 月 7 日
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 件のコメント
Jan
Jan 2022 年 5 月 7 日
@Star Strider: How does this work with string methods only?
This is 20 times slower:
function B = StepSplit(A, w)
len = strlength(A);
n = ceil(len / w);
B = strings(1, n);
c = 1;
for k = 1:n - 1
B(k) = extractBetween(A, c, c + w);
c = c + w;
end
B(n) = extractBetween(A, c, len);
end
Star Strider
Star Strider 2022 年 5 月 7 日
I did not experiment with string methods. I found an approach that worked, and went with it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by