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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by