필터 지우기
필터 지우기

how to replace 'NaN' values with any other values in a cell array

조회 수: 16 (최근 30일)
SOUVIK DATTA
SOUVIK DATTA 2019년 4월 29일
댓글: Rik 2019년 4월 30일
in this cell, how can i replace nan value?
for i=1:8
if ~isempty(d11{i})
for ix= 1:length(d11{i})
for j=1:length(d11{i}{ix})
for w=1:length(d11{i}{ix}{j})
for k=1:length(d11{i}{ix}{j}{w})
% if isnan(d11{i}{ix}{j}{w}(k))
% d11{i}{ix}{j}{1}(k)=.000001;
% end
d11{i}{ix}{j}{w}(k)(cellfun(@isnan,d11{3}{1}{1}{2}(k)))={'0'}
end
end
end
end
end
end
output: Error: ()-indexing must appear last in an index expression.
  댓글 수: 2
Rik
Rik 2019년 4월 29일
You are using parentheses twice. How deep is your cell array? 4 or 5 levels deep? And why isn't your commented code working?
Also, are you sure you want to assign a char array to your cell instead of a normal 0 (of type double)?
SOUVIK DATTA
SOUVIK DATTA 2019년 4월 30일
편집: SOUVIK DATTA 2019년 4월 30일
hello sir,
thank you for your attention. I want to replace by anything, either by a character (to write or symbolise something) or by any numerical value (for calculation). so, I tried both, none worked.
And, the array is 4 level deep. My program is skipping the commented code, means it neither shows any error nor change the 'NaN' values.
right now, I am continuing my work by changing the'NaN' value individually when it comes, before it gets stored in cell. But I want to cange it all at once. Any help would be appreciated. thank you.

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 30일
d11 = fixnan(d11);
function x = fixnan(x)
%will work no matter how many levels, including if cells are not consistent types
if isnumeric(x)
x(isnan(x)) = 0;
elseif iscell(x)
x = cellfun(@fixnan, x, 'uniform', 0);
%else other types do nothing, return unchanged
end
end

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by