Difference of elements of vector and matrix
1 次查看(过去 30 天)
显示 更早的评论
Hello,
My input is A = [1, 2, 3, 4 ; 5, 6, 7, 8], B = [1, 3], my desired output is C = [1, 3 ; 5, 7].
Is it possible to use setdiff function here? I would rather not to use loop here because of the size of the data.
0 个评论
采纳的回答
更多回答(1 个)
Davide Masiello
2022-3-24
If the values of B are to be found strictly in the first row of A, then use this
clear,clc
A = [1, 2, 3, 4 ; 5, 6, 7, 8];
B = [1, 3];
C = A(:,any(A(1,:) == B',1))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!