removing rows contain NaN element from 3D array

9 ビュー (過去 30 日間)
sermet
sermet 2016 年 10 月 21 日
編集済み: KSSV 2016 年 10 月 21 日
A(:,:,1) =
NaN NaN NaN 1.000000000000000
NaN NaN NaN 1.000000000000000
NaN NaN NaN 1.000000000000000
-0.251395732283393 0.831232695305901 0.495835045195662 1.000000000000000
-0.351395732283393 0.831232695305901 0.495835045195662 1.000000000000000
NaN NaN NaN 1.000000000000000
0.223016679421216 0.961124117481440 -0.162800465280223 1.000000000000000
A(:,:,2) =
NaN NaN NaN 1.000000000000000
NaN NaN NaN 1.000000000000000
NaN NaN NaN 1.000000000000000
-0.294547842132722 0.762119326903777 0.576555027950231 1.000000000000000
NaN NaN NaN 1.000000000000000
0.208731731285917 0.936100623203798 -0.283101903193612 1.000000000000000
NaN NaN NaN 1.000000000000000
How can I remove rows contain NaN from 3D A array? After removing each row contain NaN, sub-arrays' dimensions will not be equal. Is it allowed in Matlab?

採用された回答

Guillaume
Guillaume 2016 年 10 月 21 日
編集済み: Guillaume 2016 年 10 月 21 日
No, you cannot have different size pages in a matrix.
You could convert the 3D array into a cell array of 2D matrices and remove the nans from these matrices:
cellA = num2cell(A, [1 2]); %keep dimension 1 and 2 together
nonancellA = cellfun(@(m) m(~any(isnan(m), 2), :), cellA, 'UniformOutput', false);
Whether or not it makes later processing easier, only you can say.

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2016 年 10 月 21 日
編集済み: Andrei Bobrov 2016 年 10 月 21 日
out = arrayfun(@(x)A(all(~isnan(A(:,:,x)),2),:,x),1:size(A,3),'un',0);

KSSV
KSSV 2016 年 10 月 21 日
編集済み: KSSV 2016 年 10 月 21 日
You can take the output in cell.
[m,n,p] = size(A) ;
iwant = cell(p,1) ;
for i = 1:p
% get Nan's from first column
temp = A(:,1,i) ;
id = ~isnan(temp) ;
iwant{i} =A(id,:,i) ;
end
You can access the required matrix using iwant{1}, iwant{2}.

カテゴリ

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by