Attempted to access d(2); index out of bounds because numel(d)=1.

2 views (last 30 days)
Hello, I'm kinda new to MatLab and not much experienced in coding in general and would like to ask for some help. I am trying to create a matrix:
t = [mean(d1), mean(d2),... , mean(d18)];
d1, d2 etc are all seperate matrices of size of 1 row and 5 columns except of d1 which has 3 columns. Although I currently have it set up as above, I want a more tidy way to also get some sort of experience so I tried this:
i=1;
while i < 19;
f(i) = mean(d(i));
i = i+1;
end
t = f(1:18);
But I got this error: Attempted to access d(2); index out of bounds because numel(d)=1. Is it because what I wrote does not make sence? If yes, how can I correct it and in short what does that error mean? Thanks in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 11 Feb 2016
  1 Comment
Walter Roberson
Walter Roberson on 11 Feb 2016
D = {d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16, d17, d18};
for i = 1 : length(D)
f(i) = mean(D{i});
end
or
D = {d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16, d17, d18};
f = cellfun(@mean, D);

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!