How to combine data from 3 different arrays?

Hello,
I basically have survey data with 3 different groups/files, and I am trying to figure out how to combine them all together. The problem is that they are 4d, and each group has a different amount of people, so I am unsure how to add them together. The first 3 dimensions are the same, it is just the last dimension of the number of people that is different? Any help would be appreicated!

3 Comments

So they are A x B x C x G1, A x B x C x G2, A x B x C x G3 ? What size of output were you hoping for?
Yeah, exactly, and I am hoping for A x B x C X (G1 + G2 + G3). Help would be greatly appreciated!
*(A x B x C x (G1 + G2 + G3))

Sign in to comment.

 Accepted Answer

You can cat along the 4th dimension. Here's an example with random data:
A = 10;
B = 5;
C = 8;
G1 = 3;
G2 = 6;
G3 = 7;
data1 = rand(A,B,C,G1);
data2 = rand(A,B,C,G2);
data3 = rand(A,B,C,G3);
result = cat(4,data1,data2,data3);
size(result)
ans = 1×4
10 5 8 16

2 Comments

Thank you so much!
You're welcome! Any questions, please let me know; otherwise, please Accept this Answer. Thanks!

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 6 Feb 2023

Commented:

on 7 Feb 2023

Community Treasure Hunt

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

Start Hunting!