How to extract numbers in a string?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ali Almakhmari
le 17 Nov 2021
Réponse apportée : Image Analyst
le 17 Nov 2021
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 commentaire
Image Analyst
le 17 Nov 2021
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?
Réponse acceptée
Image Analyst
le 17 Nov 2021
For a cell array, try this:
ca = {"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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!