3D array to a column

조회 수: 3 (최근 30일)
Vadim Tambovtsev
Vadim Tambovtsev 2016년 9월 22일
편집: Stephen23 2016년 9월 22일
Suppose we have an 3D-array r=ones(m,n,k). How to make a column of all the values of "r" in the following form? example,
for r=ones(2,2,2)
the desired table should look like:
A= [r(1,1,1),
r(2,1,1),
r(1,2,1),
r(2,2,1),
r(1,1,2),
r(2,1,2),
etc, ..] .
X-grid number changes first, then changes Y-grid number, and Z-grid number is "the weakest".

채택된 답변

Stephen23
Stephen23 2016년 9월 22일
편집: Stephen23 2016년 9월 22일
Using this test matrix we can show how to rearrange into a column:
>> r = reshape(1:8,2,2,2)
r =
ans(:,:,1) =
1 3
2 4
ans(:,:,2) =
5 7
6 8
you want either
>> r(:)
ans =
1
2
3
4
5
6
7
8
or
>> reshape(permute(r,[2,1,3]),[],1)
ans =
1
3
2
4
5
7
6
8

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by