Search code examples
stringmatlabtype-conversionstring-concatenation

Meaning of specific MATLAB instruction num2str


I have been sent some complete MATLAB script. It appears that author of this code has made a specific instruction using num2str and set_param . What is the purpose of the following line:

['[' num2str(operating_point) ']']

I am interested specially of an intention of using '[' as syntax.

set_param(system_block_name, operating_point_name,...
        ['[' num2str(operating_point) ']']

Solution

  • In MATLAB rectangular braces [] create vector/matrix. By default, horizontal vector of strings concatenated into 1 string:

    ['str1','str2'] % produces str1str2
    

    So

    ['[',']'] % will print []
    

    num2str() converts number into string:

    a=10;
    my_str = ['[',num2str(a),']'] % will assign my_str = '[10]'
    

    set_param() is some function that gets 3 parameters, where 3rd one is your string