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

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 comentarios

Adam Danz
Adam Danz el 1 de Jul. de 2020
Editada: Adam Danz el 1 de Jul. de 2020
Matlab 101: Indexing
The solution will depend on how you chose those y-values in the first place.
BTW, it looks like you're missing 2 commas in your example.
Thanks for your help, Adam.
What i gave above is just an example.
I use mink(y,7) to choose those elements in y. so if
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]
z=mink(y,7); thus z=[0 3 3 4 4 5 5]
thanks
Adam Danz
Adam Danz el 2 de Jul. de 2020
Editada: Adam Danz el 2 de Jul. de 2020
How do those z values correspond to the [5,6,7,4,5,6,7] values of y?
I still don't know how those values from y were chosen.
Thanks for your response, Adam
z values [0 3 3 4 4 5 5] are the 7 minimum values of y. These were extracted using 'mink'(y) as stated earlier. These values correspond to [6 1 7 3 9 3 5] of x which I would like to find.
so this is what i wanto find [6 1 7 3 9 3 5]
Thanks
That's clearer. See the answer I added.
It works perfectly. Many thanks

Iniciar sesión para comentar.

Más respuestas (1)

Mara
Mara el 1 de Jul. de 2020
Editada: Mara el 1 de Jul. de 2020
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 comentarios

Adam Danz
Adam Danz el 1 de Jul. de 2020
Editada: Adam Danz el 1 de Jul. de 2020
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.
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

Iniciar sesión para comentar.

Categorías

Preguntada:

el 1 de Jul. de 2020

Comentada:

el 3 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by