MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

ZigZag matrix rearrange

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99055] ZigZag matrix rearrange
  • From: "Serych Jakub" <Serych at panska.cz>
  • Date: Sat, 25 Apr 2009 04:51:18 -0400 (EDT)

Dear community,
I'm trying to rearrange 8 x 8 matrix of numbers in ZigZag manner (as it is
used in JPEG comprimation algorithm http://en.wikipedia.org/wiki/Jpeg).

I have created function which does it without problems, but it does it "by
hand" and it seems to me, that it could be done by some more elegant
algorithm.
Does somebody have any idea, how to do it more elegantly?

My attempt:
zigzag[t_] := {
   t[[1, 1]],
   t[[1, 2]], t[[2, 1]],
   t[[3, 1]], t[[2, 2]], t[[1, 3]],
   t[[1, 4]], t[[2, 3]], t[[3, 2]], t[[4, 1]],
   t[[5, 1]], t[[4, 2]], t[[3, 3]], t[[2, 4]], t[[1, 5]],
   t[[1, 6]], t[[2, 5]], t[[3, 4]], t[[4, 3]], t[[5, 2]], t[[6, 1]],
   t[[7, 1]], t[[6, 2]], t[[5, 3]], t[[4, 4]], t[[3, 5]], t[[2, 6]],
   t[[1, 7]],
   t[[1, 8]], t[[2, 7]], t[[3, 6]], t[[4, 5]], t[[5, 4]], t[[6, 3]],
   t[[7, 2]], t[[8, 1]],
   t[[8, 2]], t[[7, 3]], t[[6, 4]], t[[5, 5]], t[[4, 6]], t[[3, 7]],
   t[[2, 8]],
   t[[3, 8]], t[[4, 7]], t[[5, 6]], t[[6, 5]], t[[7, 4]], t[[8, 3]],
   t[[8, 4]], t[[7, 5]], t[[6, 6]], t[[5, 7]], t[[4, 8]],
   t[[5, 8]], t[[6, 7]], t[[7, 6]], t[[8, 5]],
   t[[8, 6]], t[[7, 7]], t[[6, 8]],
   t[[7, 8]], t[[8, 7]],
   t[[8, 8]]};

Thanks for any idea

Jakub


  • Prev by Date: Re: Help with a possible bug
  • Next by Date: Re: MatrixPlot with color range bar
  • Previous by thread: Re: issues with GraphPlot
  • Next by thread: Re: ZigZag matrix rearrange