combin 4 three dimential matrices in one matrix

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 Kommentare

Those four matrices will not fill the entire 65x75x1400 matrix. Do you want them combined diagonally?
Matt J
Matt J am 5 Jun. 2019
Why can't you use CAT?
Hello Bob and Matt
you mean i can not have a 65*75*1400 with these 3 matrics?actually they are (latitude* longitude* time), time in the same but i would like put two first dimentions below eatch other because they are different in these 4 matrices.
Matt i can not use CAT because i can only put one dimention using CAT, i mean i only can combin them based on one of these three dimentions but i need to combin 2 of them it the same time
>> 16*10*1400 + 15*20*1400 + 14*15*1400 + 20*30*1400
ans = 1778000
>> 65*75*1400
ans = 6825000
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.
I think i could not explain my mean clearly lets ask it in another way:
assume that i have 2 three dimentional matrices like: A=(5 (row)*3(column)*10(third dimention)) and B=(2*2*10)
can i combin them as i have output=(7*5*10) ???? 7 rows, 5 column and 10 is the same
i should combin two first dimention and third one would be the same
is it possible in Matlab??

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Bob Thompson
Bob Thompson am 5 Jun. 2019

2 Stimmen

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 Kommentare

madhan ravi
madhan ravi am 5 Jun. 2019
+1 , admire the patience!
Jan
Jan am 6 Jun. 2019
Bearbeitet: Jan am 6 Jun. 2019
[MOVED from section for answers] Nahid Atashi 14 minutes ago:
many thanks Bob, you described very clear. this method is also fine but specifically in this case i should not have empty cells or maybe if i can fill empty cells eith NaN would be fine. anyway thank's one more
Jan
Jan am 6 Jun. 2019
@Nahid: Please post comments in the section for comments. Thanks.
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by