Create a 3D matrix from 2 2D matrix
3 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I want to create a 3D matrix from three 2D matrix with different size.
The first matrix has the size of 360x560 which contain the information of grid for x.
The second matrix has the same size (360x560) and has the grid details of z.
The third matrix has the size of 100x560 and it contain the detail of grid for y.
To simply, the size of x, y and z are 560, 360 and 100.
I would like to create a 3D matrix with a size of 100x360x560 with grid information for the x, y and z direction.
May I know how to achieve that? I have attached a test.mat file that include x, y and z.
Thanks for your help!
2 件のコメント
回答 (1 件)
Manish
2024 年 9 月 16 日
編集済み: Manish
2024 年 9 月 16 日
Hi K3iTH,
I understand that you want to create a 3D matrix (100x360x560) from the matrices x (360x560), y (100x560), and z (360x560).
You can achieve this with the help of the ‘reshape’ function. Refer to the link below for a better understanding:
Here is a code example:
% Load the data from the .mat file
load('test.mat');
% Initialize the 3D matrix
resultMatrix = zeros(100, 360, 560);
% Reshape matrices for implicit broadcasting
x_expanded = reshape(x, [1, 360, 560]); % Reshape x to broadcast over the first dimension
y_expanded = reshape(y, [100, 1, 560]); % Reshape y to broadcast over the second dimension
z_expanded = reshape(z, [1, 360, 560]); % Reshape z to broadcast over the first dimension
% Combine the matrices using implicit broadcasting
resultMatrix = x_expanded + y_expanded + z_expanded;
Hope it hepls!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!