From: DSPtree on
Could someone help me out with the code for

Vec(.) operation for multidimensional array.(eg: 4-D)

Normally
eg: A=[1 2 3; 4 5 6] vec(A)=[1 2 3 4 5 6]'

that we can find using A(:),

and so for $-D how does it come using a 'for loop'

Thanks and Regards
From: Matt J on
A(:) is applicable to all arrays, regardless of their dimension.
From: Steven Lord on

"DSPtree" <paulscot45(a)yahoo.com> wrote in message
news:1664873194.2231.1277124011336.JavaMail.root(a)gallium.mathforum.org...
> Could someone help me out with the code for
>
> Vec(.) operation for multidimensional array.(eg: 4-D)
>
> Normally
> eg: A=[1 2 3; 4 5 6] vec(A)=[1 2 3 4 5 6]'
>
> that we can find using A(:),

Not quite; remember that MATLAB is column-major. If A is [1 2 3;4 5 6] then
A(:) should be [1; 4; 2; 5; 3; 6]. To obtain [1; 2; 3; 4; 5; 6] you would
need to transpose A first, or do something like reshape(A.', [], 1).

> and so for $-D how does it come using a 'for loop'

You can use A(:) or RESHAPE for N-D arrays perfectly well -- but you may
need to use PERMUTE instead of using TRANSPOSE.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: us on
DSPtree <paulscot45(a)yahoo.com> wrote in message <1664873194.2231.1277124011336.JavaMail.root(a)gallium.mathforum.org>...
> Could someone help me out with the code for
>
> Vec(.) operation for multidimensional array.(eg: 4-D)
>
> Normally
> eg: A=[1 2 3; 4 5 6] vec(A)=[1 2 3 4 5 6]'
>
> that we can find using A(:),
>
> and so for $-D how does it come using a 'for loop'
>
> Thanks and Regards

a hint:

help permute;
% eg,
v=[1 2 3; 4 5 6];
r=permute(v,[2,1]);
r=r(:)

us