How to set all non-finite elements of a matrix to the minimum of the corresponding column?

4 vues (au cours des 30 derniers jours)
Hi,
I have a matrix m and want to set all elements that are NaN, Inf or -Inf to the minimum of the corresponding column. For example: If m(r,c) is non-finite, it should be set to the lowest finite value of column c.
How can this be done (preferably without looping)?
Thanks...

Réponse acceptée

Matt J
Matt J le 28 Sep 2013
Modifié(e) : Matt J le 28 Sep 2013
m(~isfinite(m))=nan;
minvals=min(m,[],1);
m=bsxfun(@max,m,minvals);

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation 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!

Translated by