How to extract corresponding values of x-axis based y-axis values.

조회 수: 30 (최근 30일)
Good day,
Could someone please help me on how to extract corresponding values of x-axis based on y-axis values?
x=[1,3,4,8,3,5,6,4,5,6,7,9]
y=[3,5,6,7,4,5,6,7,8,0,3,4]
I would like to extract the corresponding values of these elements; 5,6,7,4,5,6,7(values from y-axis) in x-axis.
I only know how to find a corresponding single value not multiple values.
Thanks
  댓글 수: 6
Adam Danz
Adam Danz 2020년 7월 2일
That's clearer. See the answer I added.
AUWAL ABUBAKAR
AUWAL ABUBAKAR 2020년 7월 3일
It works perfectly. Many thanks

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

채택된 답변

Adam Danz
Adam Danz 2020년 7월 2일
[z, zIdx] = mink(y,7);
xz = x(zIdx);

추가 답변 (1개)

Mara
Mara 2020년 7월 1일
편집: Mara 2020년 7월 1일
maybe use ismember:
idx = ismember(y, [5,6,74,5,67])
xvalues = x(idx)
P.S. sorry for the editing, I now read your problem correctly
  댓글 수: 2
Adam Danz
Adam Danz 2020년 7월 1일
편집: Adam Danz 2020년 7월 1일
The problem with this approach is that the last value of y will also be matched. I believe the OP is trying to isolate only the 7-element segment.
AUWAL ABUBAKAR
AUWAL ABUBAKAR 2020년 7월 1일
Thanks, Mara. It works almost percfectly except for the issue Adam mentioned. The approach also matched the last value of y.
Thank you both once again for your help

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by