array to vector conversion

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.

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 4월 15일

0 개 추천

A = rand(450,210,4);
EDIT
% 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.

댓글 수: 6

Hassan
Hassan 2011년 4월 15일
thanks a lot for the help. I think I need to do a step before using that since now it's writing the first column and then 2nd column, ... but I need first rwo,2nd row,...
A = rand(450,210,4);
A=tranpose(A(:,:,1))
A1 = reshape(A(:,:,1),450*210,1)
James Tursa
James Tursa 2011년 4월 15일
You can use the MTIMESX FEX submission to do an nD transpose on your original A array. That will turn your rows into columns and get them next to each other in memory. Then you can do the rest of the calculation as shown above. e.g.,
A = mtimesx(1,A,'T'); % Transpose the first two dims
You can find MTIMESX here:
http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensional-support
Hassan
Hassan 2011년 4월 17일
thanks for the help. I couldn't run the code. it gives me an error which says A C/C++ compiler has not been selected with mex
-setup. I don't know what should I do to fix it.
Hassan
Hassan 2011년 4월 17일
thanks Oleg for refining the code.
James Tursa
James Tursa 2011년 4월 17일
Type the following at the MATLAB command line prompt:
mex -setup
Then press Enter
Then enter the number of a C compiler such as lcc
Then press Enter again
Then try running mtimesx again.
Hassan
Hassan 2011년 4월 22일
thanks James, it's working now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2011년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by