Removing char in a mixed string column so only numerical values are left?

5 Ansichten (letzte 30 Tage)
I am trying to plot some data, but one of the columns I need has been imported with quotation marks around it (see below).
In order to plot this data I also need to get rid of the LED part in each row - how do I edit this matrix to only include the numerical values? I have apprx. 220 rows of data.
Thank you.

Akzeptierte Antwort

Star Strider
Star Strider am 9 Sep. 2019
If ‘LEDS’ is a cell array, try this:
LEDS = {'LED114'; 'LED2'; 'LED49'};
LED_Nrs = regexp(LEDS, '\d*', 'match')
Out = str2double([LED_Nrs{:}])'
producing:
Out =
114
2
49
  5 Kommentare
Stephen23
Stephen23 am 9 Sep. 2019
Bearbeitet: Stephen23 am 9 Sep. 2019
Simpler regexp output:
str2double(regexp(LEDS,'\d*','match','once'))
The most efficient solution by far:
sscanf([LEDS{:}],'LED%d')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

madhan ravi
madhan ravi am 9 Sep. 2019
Bearbeitet: madhan ravi am 9 Sep. 2019
Wanted = str2double(regexprep(LED,'LED',''))
% ^^^--- is your columns of data containing mixed data
  1 Kommentar
Sofie Lund
Sofie Lund am 9 Sep. 2019
Thank you for your response. I will try this out! I have also attached my file above as you requested

Melden Sie sich an, um zu kommentieren.


Fabio Freschi
Fabio Freschi am 9 Sep. 2019
Check erease
erease(yourString,'LED');

Kategorien

Mehr zu Variables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by