Difference of elements of vector and matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Rafal Jaremski
am 24 Mär. 2022
Kommentiert: Rafal Jaremski
am 24 Mär. 2022
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/939929/image.png)
0 Kommentare
Akzeptierte Antwort
Stephen23
am 24 Mär. 2022
A = [1,2,3,4;5,6,7,8]
B = [1,3]
[X,Y] = ismember(B(1,:),A(1,:));
C = A(:,Y(X))
Weitere Antworten (1)
Davide Masiello
am 24 Mär. 2022
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))
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!