if NaN then...
221 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Clarisha Nijman
am 2 Jan. 2019
Kommentiert: Clarisha Nijman
am 4 Jan. 2019
Dear all,
I have a function that returns me a PMatrix. But sometimes that matrix is full with nan's. The cause is known, but the best solution I found is to allow the function to compute such kind of "nan" matrices and to replace that "NaN matrix in the end by the identity matrix.
This is my actual code that works fine, uptill now.
Som=sum(sum(PMatrix));
Som(isnan(Som))=1;
if Som==1
PMatrix=eye(k,k);
end
I find this code clumsy and would prefer a more straight forward code saying:
if sum(sum(PMatrix))=NaN
PMatrix=eye(k,k)
end
But I can't figure out how to compose such a straight forward code. Does anyone has a suggestion for me?
Thank you in advance.
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 2 Jan. 2019
Which release are you using? For release R2018b or later:
if any(isnan(PMatrix), 'all')
end
For release R2018a or earlier:
if any(isnan(Pmatrix(:)))
end
Weitere Antworten (1)
Gareth
am 2 Jan. 2019
Bearbeitet: per isakson
am 3 Jan. 2019
Have you tried using the function isnan?
1 Kommentar
Siehe auch
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!