How to extract number from cell array?

3 Ansichten (letzte 30 Tage)
Heidi Mäkitalo
Heidi Mäkitalo am 13 Jun. 2019
Kommentiert: Heidi Mäkitalo am 2 Jul. 2019
I have a cell array that contains only the following text: 'Interval: 0.02 sec'. How can I extract the number 0.02 from the cell, to be used in calculations?

Akzeptierte Antwort

madhan ravi
madhan ravi am 13 Jun. 2019
cellfun(@(x) sscanf(x,'Interval: %f'),c,'un',0) % assuming follows the same pattern , turn 0 to 1 if it’s a scalar output.
  2 Kommentare
madhan ravi
madhan ravi am 13 Jun. 2019
Bearbeitet: madhan ravi am 13 Jun. 2019
OR
str2double(regexp(c,'\d+[\.]?\d*','match','once')) % where c is your cell array
Heidi Mäkitalo
Heidi Mäkitalo am 2 Jul. 2019
Sorry for the late answer but I used the str2double function and it works perfectly! Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays 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