Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I'd use Daniel's approachDaniel's approach. But just to provide an alternative:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

Note that this works because, as per sort's documentation,

The ordering of the elements in B (output) preserves the order of any equal elements in A (input)

I'd use Daniel's approach. But just to provide an alternative:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

Note that this works because, as per sort's documentation,

The ordering of the elements in B (output) preserves the order of any equal elements in A (input)

I'd use Daniel's approach. But just to provide an alternative:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

Note that this works because, as per sort's documentation,

The ordering of the elements in B (output) preserves the order of any equal elements in A (input)

deleted 11 characters in body
Source Link
Luis Mendo
  • 113.3k
  • 13
  • 80
  • 154

I'd use Daniel's approach. But since you wantjust to provide an alternative, here's one:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

Note that this works because, as per sort's documentation,

The ordering of the elements in B (output) preserves the order of any equal elements in A (input)

I'd use Daniel's approach. But since you want an alternative, here's one:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

Note that this works because, as per sort's documentation,

The ordering of the elements in B (output) preserves the order of any equal elements in A (input)

I'd use Daniel's approach. But just to provide an alternative:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

Note that this works because, as per sort's documentation,

The ordering of the elements in B (output) preserves the order of any equal elements in A (input)

added 224 characters in body
Source Link
Luis Mendo
  • 113.3k
  • 13
  • 80
  • 154

I'd use Daniel's approach. But since you want an alternative, here's one:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

Note that this works because, as per sort's documentation,

The ordering of the elements in B (output) preserves the order of any equal elements in A (input)

I'd use Daniel's approach. But since you want an alternative, here's one:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

I'd use Daniel's approach. But since you want an alternative, here's one:

m = 4; %// size of each initial "block" [~, ind] = sort(mod(0:numel(u)-1,m)+1); uNew = u(ind); 

Note that this works because, as per sort's documentation,

The ordering of the elements in B (output) preserves the order of any equal elements in A (input)

Source Link
Luis Mendo
  • 113.3k
  • 13
  • 80
  • 154
Loading