Remove '00' the first two digit to '0' in cell
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi community,
Suppose i have array in cell:
ab={'10300' '20257' '30073' '40080' '55011' '82132' '0' '0' '0'; '10321' '20258' '30084' '40091' '56024' '00822' '0' '0' '0'};
the question how change '00822' that contain '00' the first two digit to '0', so the result i want is:
ab={'10300' '20257' '30073' '40080' '55011' '82132' '0' '0' '0'; '10321' '20258' '30084' '40091' '56024' '0' '0' '0' '0'};
thx
댓글 수: 0
채택된 답변
Walter Roberson
2023년 1월 12일
Are you sure you do not want to remove all leading zeros (leaving, of course a lone 0) ?
ab={'10300' '020257' '30073' '00080' '55011' '82132' '0' '00' '0'; '10321' '20258' '30084' '40091' '56024' '00822' '0' '0' '0'}
ab_remove_00_only = regexprep(ab, '^00(?=\d)', '')
ab_remove_all_leading_0 = regexprep(ab, '^0+(?=\d)', '')
댓글 수: 1
Walter Roberson
2023년 1월 12일
After re-reading the question:
ab={'10300' '020257' '30073' '00080' '55011' '82132' '0' '00' '0'; '10321' '20258' '30084' '40091' '56024' '00822' '0' '0' '0'}
ab_zap_00 = regexprep(ab, '^00.*', '0')
추가 답변 (1개)
Karim
2023년 1월 12일
ab = {'10300' '20257' '30073' '40080' '55011' '82132' '0' '0' '0'; '10321' '20258' '30084' '40091' '56024' '00822' '0' '0' '0'}
% use the 'starts with' function to determine the locations
TF = startsWith(ab,"00")
% replace with a single '0'
ab(TF) = {'0'}
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!