필터 지우기
필터 지우기

How to reindex values from a vector

조회 수: 12 (최근 30일)
Romeo Tahal
Romeo Tahal 2020년 3월 22일
댓글: Romeo Tahal 2020년 3월 23일
Hi everyone,
I have a question I would like to ask. I have the following issue:
index = [4 2 3 1 5]
The corresponding x vector is: [0.5392 0.7805 0.5867 0.4189 0.9886]
Now I want to change the index in sequence like: index = [1 2 3 4 5]
The corresponding x vector should be [0.4189 0.7805 0.5867 0.5392 0.9886]
I've tried to use this code: x(index) = [1 2 3 4 5] to come up with the corresponding values, but the program keeps on running. I have to stop it manually. What am I doing wrong here?
Regards,
Romeo

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 3월 22일
index = [4 2 3 1 5];
x=[0.5392 0.7805 0.5867 0.4189 0.9886];
sortedX = x(index)
sortedX = 1×5
0.4189 0.7805 0.5867 0.5392 0.9886

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by