how to interpret this expression?

1 view (last 30 days)
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;

Accepted Answer

David Sanchez
David Sanchez on 23 May 2013
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]

More Answers (0)

Community Treasure Hunt

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

Start Hunting!