Sorting same rows & columns in two different matrices?

1 回表示 (過去 30 日間)
Raju
Raju 2019 年 5 月 13 日
編集済み: dpb 2019 年 5 月 13 日
I have two matrices
A =
16 2 3 13
5 11 0 8
9 7 NaN 12
4 14 15 1
B =
6 NaN 3 11
NaN 16 10 0
9 3 6 12
8 14 20 1
I want to select non-zero or no NaN values from matrix 'A'. These values are placed in certain rows:columns of the matix. I want to consider those selected rows:columns from A, and select same rows:columns in matrix B (of same szie). For small matrices, it is easier to recognise but how do we do in matrices of size 92x128. Any leads will be appreciated?

回答 (2 件)

KSSV
KSSV 2019 年 5 月 13 日
A = [ 16 2 3 13
5 11 0 8
9 7 NaN 12
4 14 15 1];
idx = isnan(sum(A,2)) ;
% pick non nan rows
A(~idx,:)

dpb
dpb 2019 年 5 月 13 日
編集済み: dpb 2019 年 5 月 13 日
Piece o' cake with logical indexing...
C=B(isnan(A)); % just return the values
ix=isnan(A); % return the pattern in logical array

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by