How to convert cell with numeric and string-nan into TYPE double

조회 수: 1 (최근 30일)
balandong
balandong 2017년 10월 3일
댓글: balandong 2017년 10월 5일
Dear all, I have a cell with the combination of number and string NaN. May I know how I can convert the content into a double type? The cell is attach together with this thread.
Thanks in advance

채택된 답변

Matthew
Matthew 2017년 10월 3일
Something like the below works fairly well. Use cellfun to search for numeric values, and save them into the doubles array. Then convert everything else into NaNs (or whatever else you want the NaNs to be).
cr_double = zeros(size(cr_manual))
cr_number = cellfun(@(x) isnumeric(x),cr_manual)
cr_double(cr_number) = [cr_manual{cr_number}]
cr_double(~cr_number) = NaN
  댓글 수: 1
balandong
balandong 2017년 10월 5일
Hi Matthew,
Thanks for the quick reply. Your suggestion work like a charm, really appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by