Can't take the mean of a 2D matrix (Array indices must be positive integers or logical values.)

1 view (last 30 days)
I have a 3D data set that I'm trying to take the mean and std along a single dimension and then average the mean or the std along the other two dimensions. Once I get the mean or the std along one dimension I have a 2d matrix. I can take the mean of the first matrix (means), but I can't with the second 2d matrix (STDs) The error I get is
Array indices must be positive integers or logical values.
This should be really simple.
%get rid of headers
data = data_set(6:2165,1:2048,1:16);
%permute data putting temporal frames first
data_frames_first = permute(data,[3,1,2]);
%average all the frames
frames_avg = mean(data_frames_first);
%permute frames back to last
frames_avg_and_last = permute(frames_avg,[2,3,1]);
%average all of our 2160 rows
frames_rows_avg = mean(frames_avg_and_last);
%finally average vertically along our 2048 columns
mean = mean(frames_rows_avg)
%take std of all frames element by element
frames_std = std(data_frames_first);
%permute frames back to last
frames_std_and_last = permute(frames_std,[2,3,1]);
%average all of our 2160 rows of stds
frames_stds_rows_avg = mean(frames_std_and_last);
This where I get the error
Error (line 29)
frames_stds_rows_avg = mean(frames_std_and_last);
Array indices must be positive integers or logical values.
Thanks.

Accepted Answer

Rik
Rik on 6 Aug 2019
You are using mean both as a function name and a variable name.
Also, if you read the doc for mean, you will notice you can explicitly set the dimension to be reduced. If I recall correctly the same is true for std.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!