Effacer les filtres
Effacer les filtres

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

16 vues (au cours des 30 derniers jours)
SOUVIK DATTA
SOUVIK DATTA le 29 Avr 2019
Commenté : Rik le 30 Avr 2019
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 commentaires
Rik
Rik le 29 Avr 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 le 30 Avr 2019
Modifié(e) : SOUVIK DATTA le 30 Avr 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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 30 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by