Remove elements from string array
조회 수: 18 (최근 30일)
이전 댓글 표시
What is the simpest way to remove string elements from an array? e.g. arr = [1, 2, 3, "x", "y", 10] would turn into [1,2,3,10]
댓글 수: 4
Guillaume
2019년 11월 26일
What is the rule that dictates which elements should be removed from the string array?
답변 (1개)
Guillaume
2019년 11월 26일
One possible way:
numericarray = double(yourstringarray); %convert string array to numeric. Text that can't be converted to numeric will end up as NaN.
numericarray = numericarray(mod(numericarray, 1) == 0); %only keep numbers that are integers. Will also remove NaNs.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!