フィルターのクリア

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 Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by