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

16 次查看(过去 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