Fill one vector with zeros when another vector is zero

I have two vectors A and B of same lengths. I wanto to replace values of A with zeros when B is 0. As follows:
[A] [B]
1 1
2 1
3 1
4 0
5 0
6 1
7 1
8 0
Then the new [A] will be...
[A2]
1
2
3
0
0
6
7
0
Any help will be much apreciated it.

 채택된 답변

madhan ravi
madhan ravi 2019년 3월 26일
편집: madhan ravi 2019년 3월 26일
A2=A.*(B~=0)

댓글 수: 5

thank you! and what if want to delete them?
so the new vector is
[A2]
1
2
3
6
7
this will delete all the zeros values in A2, what i need is to delete the values in A when B is equal to zero.
A2(B==0)=[]
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

질문:

2019년 3월 26일

댓글:

2019년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by