Effacer les filtres
Effacer les filtres

replace all the array with NaN if any of the value is NaN

1 vue (au cours des 30 derniers jours)
khan
khan le 27 Sep 2017
Commenté : Stephen23 le 27 Sep 2017
i am working with some data and the condition i want to set is that, if in the data there is NaN value in any column i want to replace that whole column with NaN values. following is a screen shot of my data structure. where i am working on the third dimension (144) of the data. Thanks in advance for help

Réponse acceptée

KSSV
KSSV le 27 Sep 2017
Modifié(e) : KSSV le 27 Sep 2017
% Generate random matrix
N = 10 ;
A = rand(10) ;
% introduce nans
idx = randsample(1:N*N,20) ;
A(idx) = NaN ;
%%Repalce columns with NaN's if any NaN'present
B = A ;
for i = 1:N
if any(isnan(A(:,i)))
B(:,i) = NaN ;
end
end

Plus de réponses (1)

Jan
Jan le 27 Sep 2017
Without a loop and bsxfun:
A = randi(9, 4, 3, 2);
A(6) = NaN;
A(:, any(isnan(A), 1)) = NaN;

Catégories

En savoir plus sur NaNs dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!