t test on each grid point between two 3D matrices (3rd dimension)

Hi guys,
I have two arrays of 25 6x6 matrices each, one per group of subjects. I'd like to perform a Student's t test along the third dimension between the two groups (i.e. each grid point in the first 25 matrices vs each grid point in the second 25 matrices). Ideally, I'd get a 2D matrix output with the t values and another 2D matrix with the p values.
I tried running the code like this:
group1 = randi(100,6,6,25);
group2 = randi(100,6,6,25);
[h,p,stats] = ttest2(group1,group2, 'dim',3,'tail', 'both')
But the stats argument output, which should be a struct with t values, df and sd if I'm not mistaken, is this:
stats(:,:,1) =
-24.8068 -11.8843 -38.5223 -20.2231 -18.5612 -35.3428
-27.7352 0.2262 -5.8083 -13.9098 -21.7295 -10.9928
-6.6216 -8.7296 -14.5600 -18.9004 -13.2651 -10.9495
-19.2140 -14.6268 -30.3848 -16.6755 -15.2337 -15.8925
-21.4499 -30.1524 -13.1650 -2.7901 -17.5884 -28.3383
-16.7520 -17.1620 -15.6470 -0.8119 -14.6905 -8.9892
stats(:,:,2) =
10.0868 14.9243 -5.0777 11.7431 16.3212 -5.5372
6.1352 30.4138 26.5283 17.5098 10.1295 19.3928
26.3016 25.3696 20.4800 17.7804 20.7051 22.1495
9.6940 17.0268 -1.7752 16.9155 15.3937 17.8125
14.6499 1.9924 22.2850 31.1101 14.5484 5.4583
13.9520 14.3620 18.0470 31.6119 18.1305 22.1092
I don't understand why it's giving me two matrices and not a struct.
If I don't specify 'dim' in the code, it gives me 25 matrices for stats!
I'm running this on Matlab R2021a.
Any ideas? Thanks a lot in advance!

 Akzeptierte Antwort

You are using the wrong form of ttest2. If you want to get the stats structure, change
[h,p,stats] = ttest2(group1,group2, 'dim',3,'tail', 'both')
to
[h,p,~,stats] = ttest2(group1,group2, 'dim',3,'tail', 'both')

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