No, if you are getting "Struct contents reference from a non-struct array object." somewhere in those two lines of code, then somehow your handles variable exists but is not a struct .
If you are using GUIDE, then there is a circumstance under which this can happen: namely that during the various CreateFcn callbacks, the handles variable has not yet been set up.
However, it does not sound as if you are putting this code into a CreateFcn callback, so something else is probably writing on top of your handles variable. We would need to see the code to say what is happening.
