sorting vectors

To anyone out there who can help!
This seems to be an easy enough problem however I cannot seem to figure it out..
I have two vectors x=[25,69,45,53] y=[160,201,199,450]
I want to have an output that will sort x from smallest to largest and then display its corresponding y values..if that doesn't make sense I am trying to get a result thatlooks like this y=[160,199,450,201]

답변 (1개)

Teja Muppirala
Teja Muppirala 2011년 5월 3일

1 개 추천

Call sort with a second output argument.
x=[25,69,45,53];
y=[160,201,199,450];
[xsorted, I] = sort(x)
ysorted = y(I)

댓글 수: 1

Erick
Erick 2011년 5월 3일
Thank you so much! I was able to figure out how to sort in basically every other way but that.

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

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2011년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by