How to make a 4-D Matrix from 1-D Array?
이전 댓글 표시
I have a 1-D array (1*11). I need to make it a 4D matrix (11*11*11*11). The number of data (11) for each dimension are the same. For example, the 1-D array is A=0:1:10. This A needs to be turned into 4-D matrix. How can I do that? How to write the code for that?
댓글 수: 3
That depends on how those 14641 elements are supposed to be related to the 11 elements you started with.
The simple answer would just be
x = 0:10;
y = repmat(x,[11 1 11 11]);
... though for many uses, it may be unnecessary to expand a vector like this at all. Again, it depends on what's actually needed.
Rik
2023년 5월 15일
The question is much too light on details to conclude this, but I suspect the final answer will include a call to meshgrid or ndgrid. All depends on what OP actually wants to happen.
Sai
2023년 5월 17일
You can refer to the below link
답변 (1개)
Rahul
2024년 9월 6일
I understand that you wish to obtain a 4-D Matrix from a 1-D Matrix of 11 data elements.
Taking the example of A=0:1:10, we can obtain the 11 x 11 x 11 x 11 matrix using 'ndgrid' function.
Here's how you can achieve it:
A = 0:1:10;
% Use 'ndgrid' to expand A into 4D
[B1, B2, B3, B4] = ndgrid(A, A, A, A);
% These 4 B1, B2, B3, B4 can be combined in any desired way to obtain
% desired result.
% For Example:
B = B1 + B2 + B3 + B4;
You can refer to the following MATLAB documentations to know more about these functions:
Hope this helps! Thanks.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!