Hello I have a 10*1 vector like A=[3,4,5,6,7,8,9,2,4,3]. I want to subtract all the elements of this vector by another 1*1 vector B=[5].
A-B doesn't work to give me [-2,-1,0,1,2,3,4,-1,-2]. How can I do this?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 17일
편집: Azzi Abdelmalek 2015년 6월 17일

0 개 추천

Maybe you mean: how to remove the element in B from A
A=[3,4,5,6,7,8,9,2,4,3]
B=3
out=setdiff(A,B)

댓글 수: 1

Image Analyst
Image Analyst 2015년 6월 17일
Wow, that doesn't "work to give me [-2,-1,0,1,2,3,4,-1,-2]." but apparently your answer is what he wanted. Did you get an advance copy of the Mind Reading Toolbox? :-)

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

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 6월 17일

0 개 추천

No, it will give this:
A =
3 4 5 6 7 8 9 2 4 3
B =
5
C =
-2 -1 0 1 2 3 4 -3 -1 -2
If you want to remove the -3 element like you have in your desired result , there are a couple of ways you can do that:
C(8) = []; % Remove the -3
C(end-2) = []; % Remove the -3
C(C == -3) = []; % Remove the -3

카테고리

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

질문:

2015년 6월 17일

댓글:

2015년 6월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by