Hi everyone,
i looking for a way to get in a new vectore 'D' , values of a vectore 'A' when the values of B are equal to the values of C
lets say i have A = [1,2,3,4,5,7,8,9,10]
and B =[11,12,13,14,15,16,17,18,19,20] ; both A and B of the same lenght,
i want to compare B with a new vector C = [11,15,20]
that returns values in A when B=C
expected output D=[1,5,10]

댓글 수: 2

"both A and B of the same lenght, "
Your examples have different lengths:
>> numel(A)
ans = 9
>> numel(B)
ans = 10
i missed the number 6 in A, it was only an example

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

 채택된 답변

Stephen23
Stephen23 2020년 2월 27일
편집: Stephen23 2020년 2월 27일
>> A = 1:10
A =
1 2 3 4 5 6 7 8 9 10
>> B = 11:20
B =
11 12 13 14 15 16 17 18 19 20
>> [idx,idy] = ismember(C,B);
>> D = A(idy(idx))
D =
1 5 10

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by