Define multiple variables at the same time in MATLAB?

前端 未结 2 1761
轻奢々
轻奢々 2020-12-30 05:28

I don\'t know if MATLAB can do this, and I want it purely for aesthetics in my code, but can MATLAB create two variables at the same time?

Example

x          


        
2条回答
  •  悲哀的现实
    2020-12-30 05:46

    Use comma-separated lists to get multiple variables in the left hand side of an expression.

    You can use deal() to put multiple assignments one line.

    [x,y] = deal(cell(4,8), cell(4,8));
    

    Call it with a single input and all the outputs get the same value.

    [x,y] = deal( cell(4,8) );
    
    >> [a,b,c] = deal( 42 )
    a =
        42
    b =
        42
    c =
        42
    

提交回复
热议问题