MATLAB: Unbalanced or unexpected parenthesis or bracket.

for loop

N=8; %N= window size (8x8)
[L,L]=size(I);
L2=L/N;
for i=N:N:L-N
for j=1:L
S= sum[[(i,j)-(i,j+1)]+[(i+2,j)-(i+2,j+1)]+[(i+4,j)-(i+4,j+1)]]-sum[[(i,j-1)-(i,j)]+[(i+2,j-1)-(i+2,j-1)]+[(i+4,j-1)-(x+4,j-1)]];
end
end
I got this eror
>>Unbalanced or unexpected parenthesis or bracket.
How to fix this? Thanx for any advance.

Best Answer

You cannot have any word such as "sum" immediately before a "[".
In MATLAB, "[" and "]" are used for building arrays, not for grouping for order of operations and not for indicating arguments to a function. You should change all of the "[" and "]" on that line to "(" and ")"