Sorting the number

1 回表示 (過去 30 日間)
Pat
Pat 2012 年 2 月 23 日
編集済み: Laura Pop 2013 年 10 月 24 日
there 10 categories,so in each category 8 values are there
category1=1 to 8, category2=9 to 16 ; ; category10=73to 80
I have values from 1 to 80,not in same order(A=1 to 80)
if i select a number for ex say am selecting 14(14 belongs to category2)so i need output as
14,15,16,9,10,11,12,13,(other values except these from 1 to 80 )
so i will have 80 values in which first 8 values belong to category 2
if i select 78
output must be
78,79,80,73,74,75,76,77,(other vales except these from 1 to 80)
please help

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 2 月 24 日
try this is code
n = 8;
x = 77;
k = rem(x-1,n)+1;
out = [x:x+n-k,x-k+1:x-1]

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 2 月 23 日
This would be a good CODY problem:
%Parameters:
nel = 8; %elements
x = 14;
%Engine
ypos = mod(x,nel);
val = circshift((x-ypos):(x-ypos)+nel-1,[0 -ypos])
  2 件のコメント
Pat
Pat 2012 年 2 月 24 日
Sean one thing in that i get nine elements,plz help,i need only 8
Sean de Wolski
Sean de Wolski 2012 年 2 月 24 日
see edit

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

カテゴリ

Help Center および File ExchangeView and Analyze Simulation Results についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by