How to extract number from cell array?

3 次查看(过去 30 天)
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?

采纳的回答

madhan ravi
madhan ravi 2019-6-13
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 个评论
madhan ravi
madhan ravi 2019-6-13
编辑:madhan ravi 2019-6-13
OR
str2double(regexp(c,'\d+[\.]?\d*','match','once')) % where c is your cell array
Heidi Mäkitalo
Heidi Mäkitalo 2019-7-2
Sorry for the late answer but I used the str2double function and it works perfectly! Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by