Discussion:
Removing 'Inf' points from matrix
(too old to reply)
Sean Takai
2010-01-08 19:40:10 UTC
Permalink
Hi all,

I know this is pretty simple but I can't get it to work right.

Say I have a matrix A = [1 2 3; 4 Inf 6; Inf 8 Inf]

and I want try to remove the Inf values from a given column, what would be the best way to do so while preserving the original number values?

I know about B = A(:,2) ~= Inf

B =

1
0
1

But is there a similar way to do the same while keeping the original values while also deleting the 0 completely?

Thanks for any help.
Nathan
2010-01-08 19:48:22 UTC
Permalink
Post by Sean Takai
Hi all,
I know this is pretty simple but I can't get it to work right.
Say I have a matrix A = [1 2 3; 4 Inf 6; Inf 8 Inf]
and I want try to remove the Inf values from a given column, what would be the best way to do so while preserving the original number values?
I know about B = A(:,2) ~= Inf
B =
     1
     0
     1
But is there a similar way to do the same while keeping the original values while also deleting the 0 completely?
Thanks for any help.
How about
A(A==Inf) = NaN

or something of the sort?
What do you mean by "is there a similar way to do the same while
keeping the original values while also deleting the 0 completely"?
I see no 0 in your A.
What format would you want your matrix in if the Inf values were
somehow deleted?


-Nathan
Andy
2010-01-08 19:50:05 UTC
Permalink
Post by Sean Takai
Hi all,
I know this is pretty simple but I can't get it to work right.
Say I have a matrix A = [1 2 3; 4 Inf 6; Inf 8 Inf]
and I want try to remove the Inf values from a given column, what would be the best way to do so while preserving the original number values?
I know about B = A(:,2) ~= Inf
B =
1
0
1
But is there a similar way to do the same while keeping the original values while also deleting the 0 completely?
Thanks for any help.
If you think about it, what you're asking doesn't make sense. You would be shrinking some rows of the matrix and not others, effectively forcing the matrix dimensions to not line up properly. You should think about just checking for a flag value while processing your matrix. Use the isinf command to check for plus or minus infinity:

A(isinf(A))=0; % sets all Infs to 0

This isn't quite what you asked, but you can tailor it to your needs.
Charlie seviour seviour
2010-04-07 09:24:08 UTC
Permalink
A(isinf(A))=0; --almost right
A(isinf(A))=[]; --deletes

Continue reading on narkive:
Loading...