Perform student t-test on 3D matrix (on each grid point)

6 views (last 30 days)
Hi I have a 3D matrix (x,y,z) and I need to perform a t-test at each grid point (x,y) to test if the mean of the values in the z direction is significantly higher than zero.
My attempt:
A=data(306,6,63); %data
for x=1:306
for y=1:6
h(x,y)=ttest(A(x,y,:),'Alpha',0.01,'Tail','right'):
end
end
I wasn't sure how to handle the z direction in the loop. I've played around this this a lot getting various errors, right now it says "The data in a paired t-test must be the same size". I want to do a one-sample test on each grid point to get a 2D output indicating which grid points are significantly different.

Accepted Answer

the cyclist
the cyclist on 1 Sep 2013
It's just a minor syntax error. Try
h(x,y)=ttest(A(x,y,:),[],'Alpha',0.01,'Tail','right');
Notice that I put in an empty array for the second argument.
(This was not particularly clear, in my opinion, from the documentation.)
  3 Comments
the cyclist
the cyclist on 1 Sep 2013
Since I did not have your data, this is the code I ran:
A = randn(306,6,63);
for x=1:306
for y=1:6
h(x,y)=ttest(A(x,y,:),[],'Alpha',0.01,'Tail','right');
end
end
Does that work for you?
If not, it could be a versioning issue. I have R2013a on Mac OS X 10.8.4.
Jaclyn
Jaclyn on 1 Sep 2013
Ah yes that's probably the issue! Never thought of that, I have 2011. I just looked up the old documentation and I got this to work:
for x=1:306
for y=1:6
h(x,y)=ttest(A(x,y,:),0,0.01,'right');
end
end
Thanks for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!