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

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 10일
What about 67?
alex
alex 2014년 5월 10일
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 2014년 5월 10일

6 개 추천

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

댓글 수: 3

alex
alex 2014년 5월 10일
편집: alex 2014년 5월 10일
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 2014년 5월 10일
편집: Azzi Abdelmalek 2014년 5월 10일
A = {'jdldi'; 'jdks5.4555h'; 'f67'}
b=regexp(A,'\d+(\.)?(\d+)?','match')
out=strjoin([b{:}],'')
alex
alex 2014년 5월 10일
thank you very much Azzi! have a nice day!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2014년 5월 10일

1 개 추천

A1 = regexp(A,'[\d*\.]*\d*','match')
A2 = [A1{:}]
out = str2double(strcat(A2{:}))
Jan
Jan 2014년 5월 10일
편집: Jan 2014년 5월 18일

1 개 추천

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

Sebastian Lopez
Sebastian Lopez 2023년 4월 19일
Thanks Jan! I wasn't aware of the isletter function

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2014년 5월 10일

댓글:

2023년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by