Did you ever see '~' symbol at return value of function?

There is a function as follow
: function [y z] = func_add_minus(a, b)
And 'func_add_minus' is called as follow
[~, zz] = func_add_minus(1,2)
I have naver seen this receive format. I don't know how can I understand '~' symbol.
Did you ever see '~' symbol at return value of function?

Answers (3)

~ means to suppress an output argument.
so
[~,zz] = func_add_minus(1,2);
means that you only want to return the 2nd output argument, zz, and not y in this case.
The ~ works since R2009b. An equivalent for former versions:
[dummy, zz] = func_add_minus(1,2);
clear('dummy'); % Useful if dummy occupies a lot of memory

2 Comments

As usual I explain, that I still have to think twice, if the final value of z is the first or the last output.

Sign in to comment.

I thank you from the bottom of my heart for all the answere you’ve gave to me. Thanks a lot

Asked:

on 13 Sep 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!