How do i extract data from 3D matrix?

3 views (last 30 days)
Prakash Raut
Prakash Raut on 22 Nov 2021
Answered: Benjamin on 23 Nov 2021
I have a matrix of size 256*256*256, i want to create a 2D matrix whose each row has information from the z direction of the original matrix, how do i do it?
  2 Comments
Prakash Raut
Prakash Raut on 23 Nov 2021
Hi James,
Here is an example of what i want (only my A is 256*256*256)
>> A
A(:,:,1) =
1 2
3 4
5 6
A(:,:,2) =
7 8
9 10
11 12
A(:,:,3) =
13 14
15 16
17 18
>> iwant
iwant =
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18

Sign in to comment.

Accepted Answer

Benjamin
Benjamin on 23 Nov 2021
[m,n,~] = size(A);
newA = reshape(permute(A,[2 1 3]),m*n,[]).';

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by