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

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.

2 comentarios

Attach your data as .mat file.
This is my file at the moment, just trying things out

Iniciar sesión para comentar.

 Respuesta aceptada

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 comentarios

Thank you for your response. That kinda worked as I wanted it to. Is there a way to do this with the entire column in one command? Such as maybe using : or end?
My pleasure.
I could not do a one-line version of my regexp call, however I devised a much better option that is a one-line call:
LEDS = {'LED114'; 'LED2'; 'LED49'};
Out = cell2mat(cellfun(@(x)sscanf(x, 'LED%d'), LEDS, 'Uni',0))
producing:
Out =
114
2
49
This approach is likely more efficient, as well. That should work with your data.
Thank you, that was exactly what I needed!
As always, my pleasure!
Stephen23
Stephen23 el 9 de Sept. de 2019
Editada: Stephen23 el 9 de Sept. de 2019
Simpler regexp output:
str2double(regexp(LEDS,'\d*','match','once'))
The most efficient solution by far:
sscanf([LEDS{:}],'LED%d')

Iniciar sesión para comentar.

Más respuestas (2)

madhan ravi
madhan ravi el 9 de Sept. de 2019
Editada: madhan ravi el 9 de Sept. de 2019
Wanted = str2double(regexprep(LED,'LED',''))
% ^^^--- is your columns of data containing mixed data

1 comentario

Thank you for your response. I will try this out! I have also attached my file above as you requested

Iniciar sesión para comentar.

Categorías

Preguntada:

el 9 de Sept. de 2019

Editada:

el 9 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by