Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to sort a vector according to another vector

1 回表示 (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2020 年 9 月 30 日
閉鎖済み: Stephen23 2020 年 9 月 30 日
I have a desired vector u of order 1x6 i.e. one row and 6 columns. Likewise I generate another random vector of same size 1x6. The arrangement of elements in that random vector is varying. Now I want to get such a random number which is nearly the same as my u vector. And also I want to re-arrange the elements of that random vector according to the arrangment of my u vector. How can I do that?

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 9 月 30 日
What about adding random values to the first vector
u = [2 1 3 6 4 2];
v = u + rand(size(u))*0.1;
Result
>> u
u =
2 1 3 6 4 2
>> v
v =
2.0032 1.0211 3.0612 6.0179 4.0297 2.0483
  1 件のコメント
Sadiq Akbar
Sadiq Akbar 2020 年 9 月 30 日
Thank you very much dear Ameer Hamza for your prompt response. No I don't mean like that. Actually the randome vector is comming from a function in which (1) the arragment of elements may not be the same as that of u. (2) in which value of elements may be any real values. (3) size of both of u and random vector is same. Suppose I get a random number in which values of the elements are nearly equal to values of u vector but the arrangement of elements in this random vector is not the same as my u vector. I want to re-arrange this random vector according to my u vector.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by