C1=[0 1 2 3 NaN 4 5 6 NaN 7 Inf 8 Inf 9];
C2=C1(finite(C1));
we get :
C2=[0 1 2 3 4 5 6 7 8 9]
I'm using R2008a version and I got a warning like this:
Warning: FINITE is obsolete and will be removed in future versions. Use ISFINITE instead.
MATLAB applications, tutorials, examples, tricks, resources,...and a little bit of everything I learned ...
``` version: '1' services: man: build: . image: my-alpine:latest ``` Dockerfile: ``` FROM alpine:latest ENV PYTH...
hey that ISFINITE function is really helpful. thanks for pointing that out !!
ReplyDeleteYou are well come!
ReplyDeletehiii, do you know how to apply that isinfinite to remove NaN elements in a matrix??
ReplyDeleteI appreciate your help!!!!
C1=[0 1 2 3 NaN 4 5 6 NaN 7 Inf 8 Inf 9];
ReplyDeleteC2=C1(isfinite(C1));
But this will also remove the Inf elements. Do you mean you want to keep those Inf elements, just remove NaN elements?
just use ~isnan(C1) instead
DeleteI have several columns and rows. When I use isfinite, it arranges everything into just one column. How do I eliminate the NaN without messing with the column arrangements? Or is there a function that allows me to ignore the NaN cells when I'm processing the data. Because then, I can just create an "if" statement.
ReplyDeleteThis link might solve your problem
Deletehttp://stackoverflow.com/questions/5202680/matlab-how-to-efficiently-remove-nan-elements-from-matrix
Thanks, Ammar.
DeleteHi FrdA, sorry I still haven't come up with a good solution to your problem.
ReplyDeleteI don't know why the matrix will be converted into a single column.
to remove NaN
ReplyDeletec1=(isnan(c1))=0;
this will place a zero where Nan were.
Hope this helps
oops
ReplyDeletethe command should be
c1(isnan(c1))=0
sorry
TTKK
I agree, haha.
Deletehow to remove inf?
ReplyDeleteIn the example, C1 contains two inf.
Deletei have a matrix.. i need to take average of 8 neighbouringg pixels. but there are some NaN values.. how can i ignore them while taking average.. ??
ReplyDeletethanks in advance.. :)
Hi Saksham, you can use the nanmean function.
Deletethanks...
ReplyDeletebut now i m facing a very simple problem.. need help..
In an image i want to assign only two colors to pixels, one with value greater than 0 and other with value less than 0... i.e say black with pixel value less than o.. and white for greater than 0..
thanks..
hi
ReplyDeletehow to remove nan from excel sheet already read in matlab?
The post is talking about how to use matlab, not excel.
DeleteThis comment has been removed by the author.
ReplyDelete