Removing Nans, converting matrix to vector

6 次查看(过去 30 天)
Hi
I have 50 x 60 x 45 double arrays, from which I want to remove the Nans, and, which I then want to convert into a (row or column) vector. I realized that the following line should do this (let C be my array):
C(isnan(C)) = [];
is this correct at all? How comes that with this line the matrix is also converted to a vector? Also, are the linear indices of the original matrix used to create the order of the elements in the row vector?
Many thanks

回答(1 个)

KSSV
KSSV 2016-6-29
Let C be you matrix of 50X60X45 matrix
C = C(:) ; % convert to column vector
C(isnan(C)) = [] ; % remove NaNs
  2 个评论
MiauMiau
MiauMiau 2016-6-29
what is the difference to mine? I dont necessarily want a column vector
KSSV
KSSV 2016-6-29
If you use K(isnan(K)) = []; to a matrix, the output will be always an array. If you want a matrix again, then using find, get the indices of NaN and replace them by your number. Then the output will be a matrix of original size.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by