MATLAB: Is Matlab returning “Unbalanced or unexpected parenthesis or bracket.”

bracketsparenthesissyntaxunbalanced

Hello, I am trying to code a program where the background changes color about every minute. In this expression:
background = backgrounds{mod(Bg_state,numel(backgrounds)}+1);
the number of beginning and end parenthesis and curly brackets are the same. Does this have something to do with bracket syntax? Thank you for your help.

Best Answer

The parenthesis overlap:
background = backgrounds{ mod(Bg_state,numel( backgrounds ) } + 1);
{ }
( )
It is not only the number of braces and parenthesis, but the must be closed in the right order also.