フィルターのクリア

how to split a vector based on value rank?

1 回表示 (過去 30 日間)
Niki
Niki 2014 年 2 月 6 日
編集済み: Niki 2014 年 2 月 7 日
y = rand(1000,1); % generate a random vector
[a b]=size(y) % a is length
[yrank,index] = sort(y) % sort small to large
t1= 500;
t2=250;
t2=250;
I want to make three vectors , Vector 1 = includs as many element as t1 (e.g. 500) Vector 2= includes as many element as t2 (e.g.250) Vector 3= includes as many elements as t3 (e.g.250)
How we give these elements to each vector ? I want to give the elements with greatest and lowest value to Vector 1 then element with greatest value (but lower than the one given to Vector 1) and element with lowest value ( but greater that that given to vector 1) placed in Vector 2 then the same for vector 3. It contineous until all the elemenst are placed in the three vectors
  1 件のコメント
Niki
Niki 2014 年 2 月 6 日
編集済み: Niki 2014 年 2 月 7 日
No one???

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

回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 2 月 6 日
shidx = [index(1:end/2), index(end:-1:end/2+1)];
vector1 = reshape(shidx(1:2:end, :).', [], 1);
vector2 = shidx(2:2:end, 1);
vector3 = shidx(2:2:end, 2);
  1 件のコメント
Niki
Niki 2014 年 2 月 6 日
this is very interesting but it is limited to the numbers I said as example. If want to have for example 300 in vector1 and 400 vector2 and 300 in vector3. then I cannot use it

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

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by