Splitting numbers of vector in multiple parts
조회 수: 3 (최근 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에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!