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

5 次查看(过去 30 天)
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...

采纳的回答

Matt J
Matt J 2013-9-28
编辑:Matt J 2013-9-28
m(~isfinite(m))=nan;
minvals=min(m,[],1);
m=bsxfun(@max,m,minvals);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by