How can i obtain column vector from 3d matrx

조회 수: 1 (최근 30일)
RADWAN A F ZEYADI
RADWAN A F ZEYADI 2021년 10월 30일
댓글: DGM 2021년 10월 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