Find the indices of one variable in another one avoiding NaNs
Show older comments
Hi!
I have two matrices, A and B, they have the same number of rows and different number of columns. Matrix A is just some numbers, matrix B is the indices. Both matrices have different amout of NaNs in the end.
I want to find the number in matrix A that matches the index in the matrix B (using the simple C = B(A)). But it doesn't work with NaNs inside the matrices. Is there some other way to do it?
A = [1 2 3 7 8; 1 5 3 NaN NaN; 1 9 3 6 NaN];
B = [2 4 5 NaN; 1 2 3 NaN NaN; 1 2 NaN NaN NaN];
C = B(A);
C = [2 7 8; 1 5 3; 1 9];
Thanks!
4 Comments
Ameer Hamza
on 3 Nov 2020
In MATLAB, matrices cannot have a different number of rows. There are syntax errors in your example. Can you show a valid example?
Daria Ivanchenko
on 3 Nov 2020
Daria Ivanchenko
on 3 Nov 2020
This is not a valid matrix, because the rows have different numbers of elements:
C = [2 7 8; 1 5 3; 1 9]; % NOT VALID
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!