3d matrix to 2d matrix

Hi guys I have a 3d matrix with values A(1:3, 1:3, 1:12) and I want to transform them into 2D matrix B where B(1,1)=A(1,1,1) B(2,1)=A(1,2,1) B(3,1)=A(1,3,1) B(4,1)=A(1,1,2)..... B(36,1)=A(1,3,12)
and I would like to to the same for 3 columns. I tried to do it with 'for' loop but it doesn't work. I'd be glad for any help ;)
for i=1:3
for l=1:12
for k=1:3
B(:,)=A(1,k,l);
end
end
end

回答(1 个)

I would use the reshape function:
B = reshape(A, [], 1);
You may have to experiment with it to get the result you want.

类别

在 帮助中心 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by