Masking out unwanted data

13 Ansichten (letzte 30 Tage)
Amit Chakraborty
Amit Chakraborty am 26 Mai 2022
Beantwortet: Jan am 26 Mai 2022
Lets say , I have 2 matrix A and B .
A = [1 0 1];
B = [ 2 5 6];
Consider that, for the first element of A ( which is 1) we are getting the first element of B ( which is 2) . and for the second element A ( which is 0 ) we are getting second element in B ( which is 5) and so on.
Now, I want to make the code in such a way that , whenever in the matrix A the code finds its element 1 it mask out element in matrix B.
Example : Matrix A : 1st element is 1 so the code will maskout ( or put zero) in the first element of B which is 2.
Thanks in advance for the help!!!

Akzeptierte Antwort

Jan
Jan am 26 Mai 2022
A = [1 0 1];
B = [2 5 6];
C = B(A ~= 1)
C = 5
% Or:
B(A == 1) = 0
B = 1×3
0 5 0

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by