How can i obtain column vector from 3d matrx

1 次查看(过去 30 天)
Hi every one
i would like to obtain a vector with dimension 153*1 from 3d array with dimension 51*71*3 ?
thank you

回答(1 个)

DGM
DGM 2021-10-30
编辑:DGM 2021-10-30
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 个评论
RADWAN A F ZEYADI
RADWAN A F ZEYADI 2021-10-30
thank you and if i want the opposit from 153*1 to 3d 51*71*3?
thanks alot
DGM
DGM 2021-10-30
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

请先登录,再进行评论。

类别

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