Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Why do I get the error message 'Unbalanced or unexpected parenthesis or bracket' ?

Asked by MathWorks Support Team on 1 Oct 2013
Latest activity Answered by MathWorks Support Team on 1 Oct 2013

Why do I get the following error message:

 
 Error: Unbalanced or unexpected parenthesis or bracket.

0 Comments

MathWorks Support Team

Products

1 Answer

Answer by MathWorks Support Team on 1 Oct 2013
Accepted answer

Explanation:

It is likely that the number of left parenthesis is not equal to the number of right parenthesis in your expression.

Common causes:

You added a left parenthesis or removed a right parenthesis from the line of code.

Solution:

Count the number of left parentheses and right parentheses on the line of code. Verify that the quantity of the two types of parentheses are equal. Add in an appropriate number of right parentheses or remove extraneous left parentheses.

Example demonstrating this error:

ParenthesisExpected.m

There is another possibility that there are the correct number of left and right parentheses, but that the MATLAB syntax is incorrect. For example the following line would result in this error because indexing a string literal is incorrect syntax within MATLAB.

>> 'Hello world'(1)

0 Comments

MathWorks Support Team

Contact us