# Finding and replacing numbers with NaN

2 Ansichten (letzte 30 Tage)
SChow am 21 Jul. 2020
Kommentiert: SChow am 21 Jul. 2020
Hello,
I have a matrix where the numbers only made up of 9 are fill values and should be replaced by NaN.;
For eg: There are numbers in all sorts of combinations : 99.999, 99999.99, 9999.9 99.999999, 999999.99 ....
A bit lost on how to proceed,
Making a list like below is not easy because there are n number of combinations which is not known
P(P==9999999.99)=NaN;
P(P==999999.99)=NaN;
P(P==9999.99)=NaN;
P(P==99999.99)=NaN;
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Image Analyst am 21 Jul. 2020
Try ismembertol(). Something like (untested)
Lia = ismembertol(P, 9, 0.0001);
P(Lia) = NaN;
Lia = ismembertol(P, 9.9, 0.0001);
P(Lia) = NaN;
Lia = ismembertol(P, 9.99, 0.0001);
P(Lia) = NaN;
Hopefully there is just a limited number of cases, like 10 or so. If you really might have dozens of possibilities then you should create a list somehow, like perhaps a for loop with sprintf() and str2double
for k1 = 1 : 10
str = repmat('9', [1, k1])
for k = 1 : length(str)
str2 = [str(1:k), '.', str(k+1:end)]
num = str2double(str2)
end
end
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
SChow am 21 Jul. 2020
Many thanks, making a list like you suggested works wonders

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Cris LaPierre am 21 Jul. 2020
I would suggest using the standardizemissing function. I don't think you are going to be able to get around having to make a list, though. I can't think of a good way for MATLAB to recognize numbers just containing 9's.
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
SChow am 21 Jul. 2020
I came across standardizemissing, however as you say making a list of all possible numbers made up of all 9s is very difficult.,

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Logical finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by