Hello,
I have been calculating means and standard deviations for columns of data, and I am getting some weird results.
I have a 1x4 cell array called Transmats that has a 6x4 matrix in each cell (type double) that contains 4 datapoints (columns) for 6 subjects (rows). Each cell in Transmats has data from a different group.
For testing, I have just used the same input data for each row in Transmats.
So for now, Transmats{1} is the same as Transmats{2}, Transmats{3}, and Transmats{4} and it looks like this:
44.4128701072509 0.302502520854340 0.302502520854340 54.9821248510404
44.4128701072509 0.302502520854340 0.302502520854340 54.9821248510404
44.4128701072509 0.302502520854340 0.302502520854340 54.9821248510404
44.4128701072509 0.302502520854340 0.302502520854340 54.9821248510404
44.4128701072509 0.302502520854340 0.302502520854340 54.9821248510404
44.4128701072509 0.302502520854340 0.302502520854340 54.9821248510404
I then calculate the group averages and standard deviations for each of my groups like so:
for g=1:4
for t =1:4
Avmats{g,t}=mean(Transmats{g}(:,t));
Sdmats{g,t}=std(Transmats{g}(:,t));
end
end
Because all my values for each subject are the same, I should get a standard deviation of 0. But this is not what happens. I get the following standard deviations in Sdmats:
7.78360568894479e-15 0 0 7.78360568894479e-15
7.78360568894479e-15 0 0 7.78360568894479e-15
7.78360568894479e-15 0 0 7.78360568894479e-15
7.78360568894479e-15 0 0 7.78360568894479e-15
Why?
The only thing I can think of is that matlab rounds the numbers differently between loop iterations for some reason (that's the only way to get different numbers in Transmats in my script, I think). Is there a way to stop this from happening?
Even weirder, if I run my script on a different PC, I get a different result. Then standard deviations for column 1 and 4 of Sdmats are 0, and columns 2 and 3 have very small numbers in them.
I'm very confused and I'd very much like my standard deviation to be 0 when I have no variability in my data.
0 Comments
Sign in to comment.