# How can i obtain column vector from 3d matrx

1 view (last 30 days)
Commented: DGM on 30 Oct 2021
Hi every one
i would like to obtain a vector with dimension 153*1 from 3d array with dimension 51*71*3 ?
thank you

DGM on 30 Oct 2021
Edited: DGM on 30 Oct 2021
Consider the example:
% create an array
s = [5 7 3];
A = reshape(1:prod(s),s)
A =
A(:,:,1) = 1 6 11 16 21 26 31 2 7 12 17 22 27 32 3 8 13 18 23 28 33 4 9 14 19 24 29 34 5 10 15 20 25 30 35 A(:,:,2) = 36 41 46 51 56 61 66 37 42 47 52 57 62 67 38 43 48 53 58 63 68 39 44 49 54 59 64 69 40 45 50 55 60 65 70 A(:,:,3) = 71 76 81 86 91 96 101 72 77 82 87 92 97 102 73 78 83 88 93 98 103 74 79 84 89 94 99 104 75 80 85 90 95 100 105
% create a vector containing all pages in the first column
B = reshape(A(:,1,:),[],1,1)
B = 15×1
1 2 3 4 5 36 37 38 39 40
##### 2 CommentsShowHide 1 older comment
DGM on 30 Oct 2021
If you have a 153x1 vector, you don't have 51x71x3=10863 elements to fill that array. They've been discarded.
You can recreate the original 51x1x3 column:
% create an array
s = [5 7 3];
A = reshape(1:prod(s),s)
A =
A(:,:,1) = 1 6 11 16 21 26 31 2 7 12 17 22 27 32 3 8 13 18 23 28 33 4 9 14 19 24 29 34 5 10 15 20 25 30 35 A(:,:,2) = 36 41 46 51 56 61 66 37 42 47 52 57 62 67 38 43 48 53 58 63 68 39 44 49 54 59 64 69 40 45 50 55 60 65 70 A(:,:,3) = 71 76 81 86 91 96 101 72 77 82 87 92 97 102 73 78 83 88 93 98 103 74 79 84 89 94 99 104 75 80 85 90 95 100 105
% create a vector containing all pages in the first column
B = reshape(A(:,1,:),[],1,1)
B = 15×1
1 2 3 4 5 36 37 38 39 40
% recreate the 51x1x3 part of A
C = reshape(B,[],1,s(3))
C =
C(:,:,1) = 1 2 3 4 5 C(:,:,2) = 36 37 38 39 40 C(:,:,3) = 71 72 73 74 75