MathGroup Archive 2009

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

Search the Archive

Re: ZigZag matrix rearrange

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99094] Re: ZigZag matrix rearrange
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sun, 26 Apr 2009 01:42:08 -0400 (EDT)
  • References: <gsuit1$dsc$1@smc.vnet.net>

Hi,

you may have a look at

http://mathworld.wolfram.com/PairingFunction.html

Regards
   Jens

Serych Jakub wrote:
> 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: ContourPlot, equation and R.H. side of equation_Plotting problem
  • Next by Date: Re: issues with GraphPlot
  • Previous by thread: Re: ZigZag matrix rearrange
  • Next by thread: Re: ZigZag matrix rearrange