hello!
i have this cell array wich may have many cells,and not only three as here.
A = {'jdldi'; 'jdks5.4555h'; 'f67'}
i want to extract only the numbers,and show them as one number
for this example i want the result to be 5.455567
any help please?
Thank you very much!

2 commentaires

Azzi Abdelmalek
Azzi Abdelmalek le 10 Mai 2014
What about 67?
alex
alex le 10 Mai 2014
in the first cell:no numbers
in the second cell:5.4555
in the third cell:67
so,i want to merge all the numbers from every cell and take the number 5.455567

Connectez-vous pour commenter.

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 10 Mai 2014

6 votes

A = {'jdldi'; 'jdks5.4555h'; 'f67'}
b=regexp(A,'\d+(\.)?(\d+)?','match')
out=str2double([b{:}])

3 commentaires

alex
alex le 10 Mai 2014
Modifié(e) : alex le 10 Mai 2014
thank you! do you have any idea of how to merge these numbers to one number?
in the first cell:no numbers
in the second cell:5.4555
in the third cell:67
so,i want to merge all the numbers from every cell and take the number 5.455567
Azzi Abdelmalek
Azzi Abdelmalek le 10 Mai 2014
Modifié(e) : Azzi Abdelmalek le 10 Mai 2014
A = {'jdldi'; 'jdks5.4555h'; 'f67'}
b=regexp(A,'\d+(\.)?(\d+)?','match')
out=strjoin([b{:}],'')
alex
alex le 10 Mai 2014
thank you very much Azzi! have a nice day!

Connectez-vous pour commenter.

Plus de réponses (2)

Andrei Bobrov
Andrei Bobrov le 10 Mai 2014
A1 = regexp(A,'[\d*\.]*\d*','match')
A2 = [A1{:}]
out = str2double(strcat(A2{:}))
Jan
Jan le 10 Mai 2014
Modifié(e) : Jan le 18 Mai 2014
A simple version:
A = {'jdldi'; 'jdks5.4555h'; 'f67'}
S = cat(2, A{:});
S(isletter(S)) = [];
The simpler the code, the less chances to insert a bug.

1 commentaire

Sebastian Lopez
Sebastian Lopez le 19 Avr 2023
Thanks Jan! I wasn't aware of the isletter function

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by