How to add zeros in cell of string

조회 수: 6 (최근 30일)
Nimas
Nimas 2023년 1월 3일
편집: Stephen23 2023년 1월 3일
Hello, I have 6x1 cell of string
'10'
'00'
'11'
'011'
'0101'
'0100'
how do i change it to
'10000000'
'00000000'
'11000000'
'01100000'
'01010000'
'01000000'
Thanks!

채택된 답변

Cameron
Cameron 2023년 1월 3일
OrigCell = {'10';
'00';
'11';
'011';
'0101';
'0100'};
zeroCell = cell(length(OrigCell),1);
zeroCell(:,1) = {'00000000'};
for xx = 1:length(OrigCell)
zeroCell{xx,1}(1:length(OrigCell{xx,1})) = OrigCell{xx,1};
end

추가 답변 (1개)

Stephen23
Stephen23 2023년 1월 3일
편집: Stephen23 2023년 1월 3일
The MATLAB approach:
C = {'10';'00';'11';'011';'0101';'0100'}
C = 6×1 cell array
{'10' } {'00' } {'11' } {'011' } {'0101'} {'0100'}
D = compose('%-08s',string(C))
D = 6×1 cell array
{'10000000'} {'00000000'} {'11000000'} {'01100000'} {'01010000'} {'01000000'}

카테고리

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