How to extract numbers in a string?

조회 수: 2 (최근 30일)
Ali Almakhmari
Ali Almakhmari 2021년 11월 17일
답변: Image Analyst 2021년 11월 17일
So I have a huge table (672 elements) and each cell has a string that involves a number and some letters at the end with a variable space between them, but I want to remove the letters and convert the string number to an actual number. For example:
cell 1: "1.32e8 Cis"
cell 2: "8.47e-2 tOE"
cell 3: "4.55e8 pov"
And so on....for 672 cells.
What I want is to convert this to
1.32e8
8.47e-2
4.55e8
  댓글 수: 1
Image Analyst
Image Analyst 2021년 11월 17일
Please be clear.
Is your data is in a table variable, or a cell array variable?
There might be different ways to do it depending on what type of variable it is. Can you attach it in a .mat file?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2021년 11월 17일
For a cell array, try this:
ca = {"1.32e8 Cis"
"8.47e-2 tOE"
"4.55e8 pov"}
ca = 3×1 cell array
{["1.32e8 Cis" ]} {["8.47e-2 tOE"]} {["4.55e8 pov" ]}
for k = 1 : numel(ca)
ca{k} = sscanf(ca{k}, '%f');
end
ca % Show again in the command window
ca = 3×1 cell array
{[132000000]} {[ 0.0847]} {[455000000]}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by