Given this:
x = 1:100;
y = 201:300;
a = 250;
I know that
x(y==a)
will return 50, the value of x corresponding to the y index where y = a. Now if a has multiple elements, I'd like to find all the values of x corresponding to all the values of y where y equals any of the values in a. For example, if
a = [250; 215; 283];
I'd like to efficiently get the array [50; 15; 83]. How can I do this?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 18일
편집: Azzi Abdelmalek 2014년 2월 18일

0 개 추천

x = 1:100;
y = 201:300;
a = [250; 215; 283];
out=x(ismember(y,a))

추가 답변 (1개)

Thomas
Thomas 2014년 2월 18일
편집: Thomas 2014년 2월 18일

1 개 추천

x = 1:100;
y = 201:300;
a=[ 215 250 283];
c=ismember(y,a)
x(c)
should give you
15 50 83

카테고리

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

태그

질문:

2014년 2월 18일

댓글:

2014년 2월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by