필터 지우기
필터 지우기

How to extract number from cell array?

조회 수: 3 (최근 30일)
Heidi Mäkitalo
Heidi Mäkitalo 2019년 6월 13일
댓글: Heidi Mäkitalo 2019년 7월 2일
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