Filter löschen
Filter löschen

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

12 Ansichten (letzte 30 Tage)
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 Kommentare
Rik
Rik am 29 Apr. 2019
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 am 30 Apr. 2019
Bearbeitet: SOUVIK DATTA am 30 Apr. 2019
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 30 Apr. 2019
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

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by