필터 지우기
필터 지우기

How to compare values of two vectors?

조회 수: 93 (최근 30일)
giancarlo maldonado cardenas
giancarlo maldonado cardenas 2022년 5월 2일
답변: Star Strider 2022년 5월 2일
Hello everyone, how can I compare values between 2 vectors? Let me explain, for example I have two vectors:
vec1= [10 20 30 40 50]% transmission
vec2= [10 20 30 40 50 60 70]; % reception
It should show me the following result:
for example 10,20,30,40,50 was transmitted but 10,20,30,40,50,60,70 were received, then the result would be 5 values were sent but 7 values were received, which would be the value 60 and 70.
Any help would be very helpful, thanks in advance.

채택된 답변

Star Strider
Star Strider 2022년 5월 2일
One option could be the setdiff function, another could be ismember
vec1= [10 20 30 40 50]; % transmission
vec2= [10 20 30 40 50 60 70]; % reception
difference = setdiff(vec2,vec1) % Use 'setdiff'
difference = 1×2
60 70
differenceidx = ~ismember(vec2,vec1) % Use 'ismember' And Negate The Result
differenceidx = 1×7 logical array
0 0 0 0 0 1 1
difference = vec2(differenceidx)
difference = 1×2
60 70
Note the order, so that the longer vector would be the first argument and the shorter vector the second argument.
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 LTE Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by