How to keep only numbers in a cell (.xlsx file)?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have an .xlsx file. In one column there are numbers and text in each cell (e.g. 0.562550 (AHV)).
How could I keep ONLY the number of each cell (e.g. ONLY the 0.562550) ??
I am uploading the file in order to understand.
Thank you in advance
댓글 수: 0
채택된 답변
Walter Roberson
2021년 2월 7일
c = readcell('test.xlsx');
data = cellfun(@(C) str2double(regexprep(C, '\(.*', '')), c)
댓글 수: 0
추가 답변 (1개)
Ive J
2021년 2월 7일
편집: Ive J
2021년 2월 7일
x = readcell('test.xlsx')
nums = cellfun(@(x)sscanf(x, '%f', 1), x)
1.4420
0.3320
0.3560
0.8530
250.8690
8.8190
댓글 수: 2
Walter Roberson
2021년 2월 7일
Good point. Though I might suggest adding a size to the sscanf() to prevent it from trying to look for more values, and as a guard against the possibility of having a second value that looked like a number in the cell.
참고 항목
카테고리
Help Center 및 File Exchange에서 Other Formats에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!