Find and convert negative number strings
Ältere Kommentare anzeigen
I need to find a negative number between terms A and B in a string. The following code find the 1x5 char '-20', but not as number -20. So I can not use it directly to for continue calculation. What is the easiest way to handle this?
cell2mat(regexp(SDstring,'(?<=Reference Level\d*).*?(?= dBm)','match'));
8 Kommentare
Birdman
am 23 Mär. 2018
What does SDstring look like? Can you share it?
Stephen23
am 23 Mär. 2018
"The following code find the 1x5 char '-20'..."
What you show is a 1x3 char, not 1x5.
Yes, it is basically to locate the number between Reference Number -50 fieldB. -50 is the term I am looking for. the code only find "-50" char, but not number.
Have tried several ways other folks suggested in forum based on their experiences, but it does not work specifically to what I prefer at this point.
Guillaume
am 23 Mär. 2018
There are two problems:
- cell2mat which is never going to convert a string of numbers into an actual number. Stephen's answer of using str2double for that is correct
- the correct regular expression to detect the number. To design the correct regular expression we need to know exactly what is allowed and what isn't. Is the number always an integer or can it be decimal. Is exponential notation (e.g 1.2e5) a possibility? Is the decimal separator always '.'? Can the number include thousands separator ,? etc.
Ivy Chen
am 23 Mär. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!