MATLAB Answers


How to extract number from cell array?

Asked by Heidi Mäkitalo on 13 Jun 2019
Latest activity Commented on by Heidi Mäkitalo on 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?


Sign in to comment.

1 Answer

Answer by madhan ravi
on 13 Jun 2019
 Accepted Answer

cellfun(@(x) sscanf(x,'Interval: %f'),c,'un',0) % assuming follows the same pattern , turn 0 to 1 if it’s a scalar output.


str2double(regexp(c,'\d+[\.]?\d*','match','once')) % where c is your cell array
Sorry for the late answer but I used the str2double function and it works perfectly! Thank you!

Sign in to comment.