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 で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!