Search code examples
matlabplottitle

One line plot title with multiple texts and num2str elements


I was wondering is there a way to put titles on MATLAB plots with text and num2str elements separated by manually specified spaces.

Here I can do it in multiple lines as below for instance:

title({['a1 =' num2str(a1)],['a2 =' num2str(a2)],['$\varphi_1$ =' num2str(phi1)],['$\varphi_2$ =' num2str(phi2)],['$\varphi_3$ =' num2str(phi3)]},'Interpreter','LaTex')

But how can I keep elements in one line with manually specified spaces in between.


Solution

  • Only have one set of square brackets and lose the curly braces, and use spaces within the strings where you want additional space.

    title(['a1 =' num2str(a1) ' a2 =' num2str(a2) ' ....
        $\varphi_1$ =' num2str(phi1) ' $\varphi_2$ =' num2str(phi2) ' ... 
        $\varphi_3$='num2str(phi3)], ... 
        'Interpreter','LaTex')