Error using accumarray in for loop with cell array

조회 수: 2 (최근 30일)
Tessa Kol
Tessa Kol 2020년 9월 9일
댓글: Tessa Kol 2020년 9월 9일
I am having trouble with using accumarray in a for loop. Hers is my code so far:
for i = 1:length(files)
% Define the range of the bins
rng_x{i} = -0.3:0.06:0.3;
% Assign the data of x-coordinate to a predefined range
disc_x{i} = discretize(expData{i,1}(:,1),rng_x{i});
x_mean{i} = accumarray(disc_x{1,i}(:,1), expData{i,1}(:,1),[11 1], @mean);
end
expData is a 2745x1 cell array and one cell contains a 4757x6 double (see picture)
disc_x is a 1x4757 cell array and one cell contains a 4757x1 double.
When I put in the command window:
x_mean = accumarray(disc_x{1,5}(:,1), expData{5,1}(:,1),[11 1], @mean);
It works fine. But as soon as I am trying to loop over the cells I get error messages. Which is kinda logical since accumarray works down colums. But how can loop over the different cells?
  댓글 수: 4
Tessa Kol
Tessa Kol 2020년 9월 9일
I got the error again. I copied the code but then instead of the x-coordinates I want to do the same thing but then for the z-coordinate:
for i = 1:length(files)
% Define the range of the bins
rng_x{i} = -0.3:0.06:0.3;
% Assign the data of x-coordinate to a predefined range
disc_x{i} = discretize(expData{i,1}(:,1),rng_x{i});
x_mean{i} = accumarray(disc_x{1,i}(:,1), expData{i,1}(:,1),[11 1], @mean);
rng_z{i} = 0.3:0.06:0.78;
% Assign the data of x-coordinate to a predefined range
disc_z{i} = discretize(expData{i,1}(:,3),rng_z{i});
z_mean{i} = accumarray(disc_z{1,i}(:,1), expData{i,1}(:,3),[8 1], @mean);
end
Error using accumarray
First input SUBS must contain positive integer subscripts.
Error in SiloV1_results_single (line 74)
z_mean{i} = accumarray(disc_z{1,i}(:,1), expData{i,1}(:,3),[8 1], @mean);
Tessa Kol
Tessa Kol 2020년 9월 9일
I found what was wrong. In my data file of z-coordinates I had values outside the defined range. This gave me an NaN, which accumarray couldn't interpret of course.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Direction of Arrival Estimation에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by