How to combine data from 3 different arrays?

3 views (last 30 days)
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
SRIPAD
SRIPAD on 7 Feb 2023
Yeah, exactly, and I am hoping for A x B x C X (G1 + G2 + G3). Help would be greatly appreciated!

Sign in to comment.

Accepted Answer

Voss
Voss on 7 Feb 2023
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
Voss
Voss on 7 Feb 2023
You're welcome! Any questions, please let me know; otherwise, please Accept this Answer. Thanks!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!