oops! Typo...
should be
for i = 1:length(theta)
% ^^
end
Two more unrelated tips:
- Always pre-allocate your loop variables (shown below)
- numel() is safer than length()
a_th = cell(size(theta)); % PRE-ALLOCATE
e_th = cell(size(theta)); % PRE-ALLOCATE
for i = 1:numel(theta) % USE NUMEL
. . .
end