MATLAB: Indexing error: ()-indexing must appear last in an index expression

cell arraysfor loopindexing

Do you know what is wrong with my indexing below? Thanks.
vars = {'Cs' 'beta' 'As' 'TCI' 'TWI' 'hs'}
tmp = cell(size(dem)) % create 20x1 supercell
out = tmp;
tmp2 = size(vars) % create 6x1 subarrays
out2 = zeros(tmp2);
for i=1:numel(dem)
for j=1:numel(vars)
*out{i} = out2(:,:,j)(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i});*
end
end
Error: ()-indexing must appear last in an index expression.

Best Answer

In MATLAB you cannot index into an array that you've already indexed into, so you cannot do this
out{i} = out2(:,:,j)(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i})
But assuming the rest of your code is OK (which I could not check), then you could define a temp variable
out2_tmp = out2(:,:,j);
out{i} = out2_tmp(Cs{i}, beta{i}, As{i}, TCI{i}, TWI{i}, hs{i})