MATLAB: How to set a range in a matrix to zero

indexmatrix manipulation

I have a matrix like:
A=[2 4 8 1 4 6]
I want to set everything to zero accept element 3-5.
The result should be
A=[0 0 8 1 4 0]
How can I do that?

Best Answer

A([1:3-1 5+1:end]) = 0