MATLAB: How to interpret this expression

operator precedence

Could you please put the braces for this expression. I mean does this expression mean
a) a( N – winLength * 2 : N )=0; this
1) a( N – ( winLength * 2 ) : N ) = 0; or
2) a( ( N – winLength ) * 2 : N ) = 0;
n the same with this expression also
b) a ( 1 : winLength * 2 ) = 0;
1) a ( 1 : ( winLength * 2 ) ) = 0; or
2) a ( (1 : winLength ) * 2 ) = 0;

Best Answer

Let us suppose
a = [1 2 3 4 5 6 7 8]; winLength = 3; N = 7;
- a( N - winLength * 2 : N )=0 -> elements from N-winLength*2 till element N is zero: N-winLength*2 = 7-3*2=1 -> a(1:7)=0 a = [0 0 0 0 0 0 0 8]
- a( N - ( winLength * 2 ) : N ) = 0 -> same than above
- a( ( N - winLength ) * 2 : N ) = 0 -> (N-winLength)*2=(7-3)*2 =4*2=8 -> a(8:7) -> this produces an empty matrix for the example presented, but I'm sure you can think about any other example.
- a(1:winLength*2) = 0 is the same than a(1:(winLength*2)) = 0 -> a(1:3*2) = a(1:6) = [1 2 3 4 5 6]
- a((1:winLength)*2) = a((1:3)*2) = a(1:3)*2 = [2 4 6]