MATLAB: How to get braces to show in the plot’s legend

bracesinterpreterlatexlegendMATLABplot

I have two different inputs in my legend:
'\sigma'
'E{r}'
as shown in:
>> legend('\sigma','E{r}');
'\sigma' is in the format I want as a greek letter. However, the braces in 'E{r}' do not show and instead output as 'E r'. How can I have the braces show?

Best Answer

To have the curly brackets show, place a backslash before the curly bracket.
>> legend('\sigma','E\{r\}');
This behavior is expected and is due to which interpreter you use. For this specific case, the 'Tex' interpreter is being used. For a more detailed list of all possible interpreters, please refer to the following link below:
Each interpreter has a list of special characters that defines a set behavior. To exit the behavior, a delimiter such as '\' is required.