0
$\begingroup$

I have a 3x6 matrix a:

a = {{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}, {13, 14, 15, 16, 17, 
   18}}

What I want is to end up with 6 1x3 arrays,

{miniOut, minimaOut, curvaturesMiniOut, maxiOut, maximaOut, curvaturesMaxiOut}

such that miniOut = {1,7,13}, minimaOut = {2,8,14} etc.

My attempt is:

stuff = Table[{miniOut[[n]], minimaOut[[n]], curvaturesMiniOut[[n]], 
    maxiOut[[n]], maximaOut[[n]], curvaturesMaxiOut[[n]]} = 
   a[[n]], {n, 1, Length[a]}]

But it says

Symbol miniOut in part assignment does not have an immediate value.

and the same for the other variables.

Do I need to pre-define the arrays in advance and set all the elements to 0?

$\endgroup$
4
$\begingroup$

It seems you are looking to store each column of a into separate variables. There is no need to do this element-wise. The easiest way is to use Transpose on a so that the columns become rows: in other words, the columns become the elements at level 1 in Transpose[a]. Then you can assign them all simultaneously:

{miniOut, minimaOut, curvaturesMiniOut, maxiOut, maximaOut, curvaturesMaxiOut} = Transpose[a]
$\endgroup$
  • $\begingroup$ What an idiot, sure! Thanks, sorry! $\endgroup$ – SuperCiocia Nov 24 '16 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.