MATLAB Answers

array to vector conversion

45 views (last 30 days)
Hassan on 15 Apr 2011
I have a 3-dimensional array A which has 450 rows,210 coulms, 4 layers. I want to make a regression between A(450,210,1) and A(450,210,3), A(450,210,2) and A(450,210,4). For that I need to convert the array to 4 vecotrs. I don't know how to do that. I tried Reshape function but couldn't get what I want. Any help is appericiated.

Accepted Answer

Oleg Komarov
Oleg Komarov on 15 Apr 2011
A = rand(450,210,4);
% Switch 2nd dim with 1st
A = permute(A,[2,1,3]);
% Reshape into vector each layer
A = reshape(A,450*210,4)
Each column now is the vectorized layer.
Hassan on 22 Apr 2011
thanks James, it's working now.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!