フィルターのクリア

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
  1 件のコメント
Romeo Tahal
Romeo Tahal 2020 年 3 月 23 日
Thank you, Cris

サインインしてコメントする。

採用された回答

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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by