MATLAB: Best practice for saving only one output from a vector-outputting function

best practicesvector output

What's the proper way to request only one variable from a vector outputting function, i.e.
[WantThis DontWantThis] = myfun(x, y, ... )
In the past I've just saved the DontWantThis output as a variable called trash and not made reference to it again. This seems rather unprofessional. Is there a cleaner way?

Best Answer

Simply
WantThis = myfun(x, y, ... )
if you just need/want the first output. More generally
[a, b, c, d] = myfun(x, y, ... )
even if there could be more output args ( e, f, g, ..).
If don't want to name args that you don't need, which are preceding args that you do need, you can use ~ as a placeholder:
[~, ~, c, ~, e] = myfun(x, y, ... )
Note that ~ is supported since 2009 if I remember well (edit: ref).