Conversion of cell element to double
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Digvijay Rawat
am 28 Dez. 2015
Kommentiert: John Manalo
am 28 Mai 2020
Hello.
I want to convert a cell element to double array element. I know the command to do this is str2double but the problem is that the cell element has a number along with a letter that I want to omit. I will try to explain it through the following example.
Cell element: '123456789 a'
Double element (by using str2double): NaN
I want to retain just the numeric part of the cell element. So I would want 123456789 as the double element in the above example. Can anyone please help as to how to go about this?
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 28 Dez. 2015
a={'123456789 a' '455'}
b=regexp(a,'\d+','match')
c=cellfun(@(x) str2double(x{1}),b)
3 Kommentare
Weitere Antworten (1)
Jan
am 28 Dez. 2015
Or:
a = {'123456789 a' '455'}
c = cellfun(@(x) sscanf(x{1}, '%g', 1))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion 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!