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.

채택된 답변

Rik
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
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by