convert double NaN to string NaN

조회 수: 38(최근 30일)
Daneisha Blair
Daneisha Blair 2021년 8월 24일
댓글: Daneisha Blair 2021년 8월 24일
I have a cell array with NaN as shown in the image. How can I convert NaN to string NaN meaning instead of of seeing NaN in the array, I want to see "NaN".
I have tried this: TC(cellfun(@(x) any(isnan(x)),TC,'UniformOutput',false)) = {"NaN"}; but no success.
Any help is appreciated.

채택된 답변

KSSV 2021년 8월 24일
A = NaN(2,5) ;
C = arrayfun(@num2str,A,'UniformOutput',false)
C = 2×5 cell array
{'NaN'} {'NaN'} {'NaN'} {'NaN'} {'NaN'} {'NaN'} {'NaN'} {'NaN'} {'NaN'} {'NaN'}
  댓글 수: 5
Daneisha Blair
Daneisha Blair 2021년 8월 24일
I got it :) . string(arrayfun(@num2str,A,'UniformOutput',false)).

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

추가 답변(1개)

darova 2021년 8월 24일
Try num2str
a = {nan 1 nan};
ans = 1×2 cell array
{'NaN'} {'NaN'}
  댓글 수: 1
Daneisha Blair
Daneisha Blair 2021년 8월 24일
This didn't give me quite what I was looking for.
For clarification, TC is in the structure of:
TC = {["Mercury","Gemini", "Apollo"; ...
"Skylab", "Skylab B","ISS"], ...
"Skylab","Skylab B"]}
% Output array
TC = cellfun(@(x) nan(size(x,1),1) ,TC,'UniformOutput',false)
which created double NaN
However, I want it in string NaN, like this {'NaN'}
Hope this help.

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

Community Treasure Hunt

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

Start Hunting!

Translated by