suppressing output variables in matlab

前端 未结 2 1524
春和景丽
春和景丽 2020-12-12 07:50

I am using a function with multiple outputs in Matlab, but am only interested in one of the outputs. I would like to suppress the other output variables (i.e. avoid them bei

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 08:33

    Replace any output variables you don't want with a ~ character.

    E.g.

    [~,I] = max(matrix);
    

    This pattern has an advantage over clear in that the MATLAB interpreter and just-in-time compiler can avoid the memory and CPU costs of calculating ignored variables.

    Edit

    Here is the documentation and a blog post by Loren Shure on this use of ~. I can't find any definite information about use of ignored variables for eliminating unnecessary computation.

提交回复
热议问题