MATLAB: How to assign the values of multiple variables in one line using vector notation

MATLAB: How to assign the values of multiple variables in one line using vector notation

MATLAB

Given two variables ‘var1’ and ‘var2’, the goal is to assign these variable to values 1 and 2 in one line using vector notation.
How can this be done?

Best Answer

  • This can be done using the function ‘deal’, which for the particular example would look as follows,
    >> [var1, var2] = deal(1, 2)
    var1 =
    1
    var2 =
    2
    For more information visit the corresponding documentation page for function ‘deal’,
  • Add a Comment

    Your email address will not be published. Required fields are marked *