Filter löschen
Filter löschen

Extract number out of a string in a cell

1 Ansicht (letzte 30 Tage)
Fiboehh
Fiboehh am 29 Apr. 2011
Hellow, i have a cell with dimension 14x1 and in every cell there is a string. My cell is like this:
testobject // object name
29-Apr-2011 17:36:49 // date and time
SD // operator
HeNe Laser // Source Type
0.02 // Half source size [mm]
6 // Number of detectors
1,3,6,9,12,15 // Detectors used
0.5 // Half detector size [mm]
8 // Number of slices
15 // Height object first slice [mm]
-0.5 // Lineair step per slice [mm]
100 // Half distance source detector [mm]
0.9 // Rotation angle in degrees
128 // Number of rotations
now i want to use the numbers before the // . So i have to extract the numbers in the begin of the string to integers. Anyone knows how? Thx in advance

Akzeptierte Antwort

Doug Eastman
Doug Eastman am 29 Apr. 2011
You could do something like this:
data = cellfun(@(x)sscanf(x,'%f'),a(5:end))
Where a is the name of your cell array. That will work for all the elements that have one number in them.
If you need to get all the numbers in the Detectors used row, you could do something like this for that particular row:
detectors = sscanf(a{7},'%d%*[,]')
In general I recommend reading the documentation and examples for sscanf.

Weitere Antworten (1)

Fiboehh
Fiboehh am 29 Apr. 2011
Thx man, it works fine. Many thanx!!

Kategorien

Mehr zu MATLAB 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