필터 지우기
필터 지우기

sort a vecrtor

조회 수: 2 (최근 30일)
Andrea
Andrea 2012년 6월 1일
I have a vector: a = [1 5 7 2 6 8 9 0 2] and b=[5 8 1 0 3 6 9 8 2] (both have the same size) I want to sort vector 'a' and accordingly vector 'b'.
a = [1 5 7 2 6 8 9 0 2] ;
b = [5 8 1 0 3 6 9 8 2] ;
[a1,ind]=sort(a) for i=1:length(a1)
b1(1,i)=b(1,ind(1,i));
end
It works. But I am wondering if there is a more professional way to get ride of this "for i=1:length(a1)" loop?
Thanks in advance.

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 6월 1일
  댓글 수: 1
Andrea
Andrea 2012년 6월 1일
wow, Thanks. It is the briefest, fastest and cutest answer I've ever got!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by