combin 4 three dimential matrices in one matrix
4 ビュー (過去 30 日間)
古いコメントを表示
Hello friends,
i have 4 matrices with 3 difffernt dimentions, like A=(16*10*1400) ; B=(15*20*1400); C=(14*15*1400); D=(20* 30*1400)
i would like to have a matrix like: out=(65*75*1400);
I can not use cat and also i want to put 2 first dimentions below eatch other not only 1 dimention
any suggestion?
thank's in advance
6 件のコメント
Bob Thompson
2019 年 6 月 5 日
I think it would be best if you gave a small sample of how you want the information to be combined.
To address the 65x75x1400 question from earlier, you CAN put those your four arrays into an array of that size, but as Stephen brought up you will only have ~1.8 of the 6.8 million elements filled.
採用された回答
Bob Thompson
2019 年 6 月 5 日
You cannot directly combine a 5x3x10 and a 2x2x10 matrix into a 7x5x10 matrix within Matlab because the direct combination of matrices requires that all size dimensions of a matrix, except the size in the dimension being combined, are equal in value. For example if you have a 2x2 (4 elements) and a 2x3 (6 elements) you can combine them in a column direction resulting in a 2x5 (10 elements). You cannot, however, combine them in the row direction.
A = [ 1 2 ;
3 4 ];
B = [ 5 6 7;
8 9 10];
% Combine by column dimension
C = [A B];
C =
[ 1 2 5 6 7 ;
3 4 8 9 10];
% If you try combining by rows (non-equal dimension size)
C = [A; B];
C =
[1 2;
3 4;
5 6 7;
8 9 10];
% You cannot do ^ this because what happens when you try to call C(1,3). Nothing exists in this cell. If you try this you will receive a 'dimension assignment mismatch' error.
Additionally, combining matrices in Matlab requires that the combined array contains the same number of elements as the sum of the parts. In our example 2x2 combined with 2x3 this rule is upheld (4 + 6 = 10).
In both of your requests, 5x3x10 and 2x2x10, and the actual problem, you fail to meet both of these requirements. In the two matrix reiteration you gave you only have one dimension that has the same length, so it is impossible to perfectly match a 'side' of the two boxes of data you have to make a single larger box. Additionally, your request for one giant box, 7x5x10 does not work either because it contains 350 elements, but the sum of the parts is not equal. (150 + 40 = 190 ~= 350)
If you do want to put this information into a single array it is possible to create a large array first, and then populate part of it with the blocks of data you have. However, as was mentioned earlier, because you do not have the same number of elements in your parts as are in the large array, then a significant portion of your large array will be empty values. If you are ok with that, then this is the method for proceeding in Matlab. If not then you need to look at a different method for organizing your data, or look into a different program.
A = randi(100,16,10,1400);
B = randi(100,15,20,1400);
C = randi(100,14,15,1400);
D = randi(100,20,30,1400);
large = nan(65,75,1400);
large(1:16,1:10,:) = A;
large(17:31,11:30,:) = B;
large(32:45,31:45,:) = C;
large(46:65,46:75,:) = D;
There are more efficient ways of accomplishing this, which is why I originally asked how you wanted your data organized within your array (because you have lots of empty space to work with), but this is the basic concept.
4 件のコメント
Bob Thompson
2019 年 6 月 6 日
Using nan to create the array in the first place has already filled all elements with NaN values. Only the elements which were replaced with your smaller matrices will not be NaN values.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!