Splitting numbers of vector in multiple parts
18 ビュー (過去 30 日間)
古いコメントを表示
I have a vector which can vary in length, e. g. V' = [2022024 2023074 2022044 2023014 2023054]. Now my problem is that I need to split each number into specific parts:
2022024 -> 2022 024
2023074 -> 2023 074
...
Does anyone know how to do this in a loop?
Thanks in advance
0 件のコメント
採用された回答
Bruno Luong
2023 年 7 月 25 日
編集済み: Bruno Luong
2023 年 7 月 25 日
If string output is desired
V = [2022024 2023074 2022044 2023014 2023054]
c = mat2cell(char(arrayfun(@num2str,V,'unif',0)),ones(length(V),1),[4 3])
string(c)
0 件のコメント
その他の回答 (4 件)
Bruno Luong
2023 年 7 月 25 日
編集済み: Bruno Luong
2023 年 7 月 25 日
If numerical value output is desired
V = [2022024 2023074 2022044 2023014 2023054]
[floor(V/1000); mod(V,1000)]'
0 件のコメント
Sachin Hegde
2023 年 7 月 25 日
V= [2022024 2023074 2022044 2023014 2023054];
V = num2str(V);
tkn = regexp(V,'(\d+)(\d{3})','tokens');
V_split = str2double(vertcat(tkn{:}))
0 件のコメント
Bruno Luong
2023 年 7 月 25 日
編集済み: Bruno Luong
2023 年 7 月 25 日
V = [2022024 2023074 2022044 2023014 2023054]
s = string(V)';
s = [extractBefore(s,5) extractAfter(s,4)]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!