How to make a QuickSort for 2 vectors?

1 回表示 (過去 30 日間)
Thomas Nell
Thomas Nell 2018 年 12 月 12 日
コメント済み: James Tursa 2018 年 12 月 13 日
Hey guys,
I have 2 vectors here, time [23 4 8 9 21 3 11 15 17 2] and signal [12 14 11 13 16 5 31 21 9 3]. What I want do is quicksort time into ascending order (i.e time =2 3 4 8 9 11 15 17 21 23] ). However, I also want the signal to rearrange itself accordingly, so it becomes [3 5 14 11 13 31 21 9 16 12]. How would I go about this???
Kind regards,
Tom
P.S I'm not allowed to use the sort command

回答 (1 件)

James Tursa
James Tursa 2018 年 12 月 12 日
編集済み: James Tursa 2018 年 12 月 12 日
See the 2nd output of the sort( ) function, and use that as an index to rearrange your signal. E.g.,
[t,x] = sort(time);
s = signal(x);
  4 件のコメント
Thomas Nell
Thomas Nell 2018 年 12 月 12 日
yes sir, it is
James Tursa
James Tursa 2018 年 12 月 13 日
What have you done so far? Are you having trouble getting started? Are you getting errors in your code? Do you have a working quicksort routine and just need to figure out how to get the indexes? Or ...?

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

カテゴリ

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