MATLAB Answers

save matrix in loop to 3D matrix (storage all inkomming matrix)

1 view (last 30 days)
Nik Rocky
Nik Rocky on 3 Jul 2020
Commented: Nik Rocky on 4 Jul 2020
I read multiple .mat-files with matrix M x-y-axis (5x2doubles) and have to save it. I think, the better way is to create a 3D-matrix - z-axis. Later, i have to make mean and std trow all z-axis elements. How can i do it?
Please think about - i get a matrix M in the loop, by load(MAT_File)
Thank you in advise!


Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 3 Jul 2020
M = cell(n, 1); % n - number of files
for k = 1:n
M{k} = load(filenames{k}); % assuming you saved filenames in a cell array
M = cat(3, M{:});
MEAN = mean(M, 3)


Show 1 older comment
Nik Rocky
Nik Rocky on 4 Jul 2020
MEAN = mean(M_test, 3);% Perfect!
STD = std(M_test, 3);% Error
Error using var (line 179)
W must be a vector of nonnegative weights, or a scalar 0 or 1.
Error in std (line 51)
y = sqrt(var(varargin{:}));
Error in Plot_ROC_03_07_20 (line 120)
STD = std(M_test, 3);

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!