MATLAB: How To Efficiently Remove NaN Elements from Matrix

后端 未结 5 1064
猫巷女王i
猫巷女王i 2020-12-05 01:13

I am looking for a way to remove the NaN numbers from a matrix in MATLAB efficiently (i.e. without using a for loop)

I will provide a quick example to illustrate wha

5条回答
  •  醉话见心
    2020-12-05 01:21

    The best way is

    M(any(isnan(M),2),:)=[]
    

    which will remove any row that contains at least one NaN.

提交回复
热议问题