Creating a matrix based on sorted values from another matrix

1 回表示 (過去 30 日間)
stelios loizidis
stelios loizidis 2023 年 2 月 23 日
コメント済み: stelios loizidis 2023 年 2 月 23 日
Hello,
I have matrix A, 1X5, and matrix B, 1X5
% Matrix A
A=[0.0012,0.0011,0.0011,0.0014,0.0015];
% Matrix B
B=[40.5,66,12,22,58.91];
I want to create matrx C, 2X5 as shown below,
% Matrix C 2X5
C=[0.0011,0.0011,0.0012,0.0014,0.0015;66,12,40.5,22,58.91];
That is, to sort the data of matrix A in ascending order but at the same time have the corresponding value from matrix B. For example 0.0012 corresponds to 40.5 and etc. As shown in matrix C. How is this done?

採用された回答

Askic V
Askic V 2023 年 2 月 23 日
[As, ind] = sort(A);
C = [As;B(ind)]
  1 件のコメント
stelios loizidis
stelios loizidis 2023 年 2 月 23 日
It works!!!! Thanks for your valuable help!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by