Hello, I have 2 matrices 52x21x49. Here x=52, y=21 and each of these 'tiles' have 49 values.
I want to do a ttest on each tile to see if the 49 values in each tile of matrix A is drawn from a different distribution than the same tile in matrix B.
Therefore my h and p should = 52x21 each. Is there a smart way of doing this without a for loop?
Thanks, S

 Respuesta aceptada

Tom Lane
Tom Lane el 9 de Mzo. de 2012

0 votos

Since TTEST wants to work along the first dimension, you can just move that dimension to the front using PERMUTE. Then use SQUEEZE to get rid of the extra dimension. Something like this:
>> a = rand(3,4,5);
>> b = rand(3,4,5);
>> [h,p] = ttest2(permute(a,[3 1 2]),permute(b,[3 1 2]));
>> squeeze(h)
ans =
0 0 0 0
0 0 0 0
0 0 1 0
>> squeeze(p)
ans =
0.6347 0.2035 0.2729 0.6062
0.7198 0.7766 0.0945 0.5118
0.2029 0.5078 0.0111 0.3311

2 comentarios

sas0701
sas0701 el 12 de Mzo. de 2012
Perfect! Thank you:)
Henry Fu
Henry Fu el 21 de Mzo. de 2021
Another way to do this is to specify dimension in ttest.
e.g. [h,p] = ttest(a,b,'Dim',3);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Mzo. de 2012

Comentada:

el 21 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by