Usage of tilde as output

4 views (last 30 days)
suman Dahal
suman Dahal on 14 Jan 2013
Commented: Nicholas Bitler on 25 Nov 2020
i have understood that tilde ignores the output but what does tilde do here,please explain me the logic behind this,
for k=1:n
[~, m]=max(abs(U(k:n,k)))
end
  1 Comment
Jan
Jan on 15 Jan 2013
Edited: Jan on 15 Jan 2013
@suman: You have understood, that the tilde ignores an output and ask for what the tilde does. Azzi and Walter reply, that the tilde ignores an output. This seems to be a tautological strategy.
I've move the code from the title to the body of the question.

Sign in to comment.

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 14 Jan 2013
Edited: Azzi Abdelmalek on 14 Jan 2013
[a,b]=max(sin(1:100))
% a is the maximum value
% b is the corresponding index
~ is used to ignore a ( to avoid using memory).
  3 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 15 Jan 2013
Edited: Azzi Abdelmalek on 15 Jan 2013
When you clear a variable, I think it's avoid using memory
Walter Roberson
Walter Roberson on 15 Jan 2013
The memory is still used temporarily, only to be thrown away again afterwards.
Consider for example,
[~, fs] = wavread('SomeSound.wav');
wavread() does not know that the first output is being thrown away, so it will go trough all the trouble of decoding the sound and storing it and returning it. And then it will be thrown away.
[~, b] = max(...)
is the equivalent in MATLAB of
[a, b] = max(...)
clear a
except for using a variable name that is not otherwise used (and probably not needing an actual entry in the workspace, which only matters if the workspace already has 65533 entries in it.)

Sign in to comment.


Walter Roberson
Walter Roberson on 14 Jan 2013
The tilde there ignores the first output of max(), which is the value of the maximum. The second output of max is left intact; it is the index of the maximum.
Because "m" is being overwritten in every iteration of the loop, the code is equivalent to the loop-less
[~, m] = max(abs(U(n, n)))
which would return 1 as it is max() of a single element.
  3 Comments
Rik
Rik on 24 Nov 2020
That depends on what you mean by 'typical'. On my keyboard it is a dead key just under escape (shift-backtick). 'Dead key' in this context means that hitting it doesn't do anything until I type another key. This allows the formation of ã and ñ.
Nicholas Bitler
Nicholas Bitler on 25 Nov 2020
And there it is...Thanks Rik

Sign in to comment.

Categories

Find more on Data Type Identification in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!