Can't take the mean of a 2D matrix (Array indices must be positive integers or logical values.)
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Rik
2019-8-6
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.
2 个评论
Rik
2019-8-8
You're welcome. If my answer solved your problem, please consider marking it as accepted answer. If not, feel free to comment with your remaining issues.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!