Convert negative and out of defined range data to NaN
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Niklas Weichbold
le 21 Nov 2021
Commenté : Niklas Weichbold
le 21 Nov 2021
Hello, my problem is that I have a matrix of 9 columns and want the quality of the data shown in a special range (as shown in "lo"=minimum size and "hi"=maximum size). If data is not in this range it should be shown as NaN.
My problem is that only data with the size 0(Zero) is shown as NaN, but not the ones outside my defined range (not even the negative data).
lo = [0.01 2.4 192 15 4 3 140 0 1];
hi = [1.4996 17.1 238 114 11 34 180 100 16];
for i=1:9
isnan(num(:,i)<lo(i));
isnan(num(:,i)>hi(i));
end
Thanks in advance!
0 commentaires
Réponse acceptée
DGM
le 21 Nov 2021
Modifié(e) : DGM
le 21 Nov 2021
You should be able to do something like this:
lo = [0.01 2.4 192 15 4 3 140 0 1];
hi = [1.4996 17.1 238 114 11 34 180 100 16];
A = randi([0 200],5,9)
A(A<lo | A>hi) = NaN
This sort of implicit array expansion should work in R2016b and newer versions.
That's a lot of NaNs, but bear in mind that the random matrix used in the example isn't exactly tailored to stay within bounds.
4 commentaires
DGM
le 21 Nov 2021
% test array
A = randi(9,10,10);
A(A<3) = NaN
B = A(~isnan(A(:,1)),:) % remove rows
nanspercol = sum(isnan(B),1);
B = B(:,nanspercol<=size(B,1)/4) % remove columns
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations 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!