create a new array without nan

조회 수: 3 (최근 30일)
Ricky
Ricky 2013년 6월 3일
Hello Everyone,
I have a 2D array of size 672*8 in which I have several rows where in first and second column I have a value and in the other there is a nan value. There are also other rows which have values in all the columns. I want to create two new arrays so that first array only contains those elements which have nan in them and second in which there is no nan element.
For eg
Row 12: 517 2850 NaN NaN NaN NaN NaN NaN
Row 13: 652 2037 169 2243 44 2443 -2 2644

답변 (2개)

Daniel Shub
Daniel Shub 2013년 6월 3일
Starting with some dummy data
x = [[randn(10, 2), nan(10, 6)]; [randn(10, 2), randn(10, 6)]];
x = x(randperm(length(x)), :);
The two matrices you want are
a = x(isnan(x(:, 3)), :);
b = x(~isnan(x(:, 3)), :);

Andrei Bobrov
Andrei Bobrov 2013년 6월 3일
A - your array
c = accumarray(any(isnan(A),2) + 1, (1:size(A,1))',[],@(x){x});
out = cellfun(@(x)A(x,:),c,'un',0);

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by