Reputation: 73
I want to calculate the standard error of multiple matrices concatenated into one:
cd C:\User\Aisk_000\Desktop\A\NC\Subjects\2014A\
A = dlmread('weights.txt');
cd ../3169A
B = dlmread('weights.txt');
cd ../3350A
C = dlmread('weights.txt');
cd ../3607A
D = dlmread('weights.txt');
cd ../4073A
E = dlmread('weights.txt');
%concatenate
x = cat(5,A,B,C,D,E)
y = mean(x,5) %calculate the average
z = std( x ) / sqrt( length( x )) %Calculate standard error
The output from z
is a 5-D double
, same as the one for x
. However, I realized that the system calculated the standard error of each matrix instead of the overall concatenated matrix. I know that it has something to do with the number "5", but I'm not sure where to put it in the code for z
.
Upvotes: 2
Views: 756
Reputation: 125854
The first argument to cat
isn't the number of matrices you are concatenating, it's the dimension along which you want to concatenate them. Since your matrices are all 2-D 16-by-16 matrices, it makes sense to concatenate them along the third dimension, stacking them into a 3-D matrix.
x = cat(3, A, B, C, D, E);
You can then use mean
and std
, specifying 3
as the dimension along which to perform the calculation:
y = mean(x, 3); % Mean along dimension 3
z = std(x, 0, 3)./sqrt(size(x, 3)); % Standard error along dimension 3
Upvotes: 1