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 Kommentar

Jan
Jan am 15 Jan. 2013
Bearbeitet: Jan am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 14 Jan. 2013
Bearbeitet: Azzi Abdelmalek am 14 Jan. 2013

1 Stimme

[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 Kommentare

James Tursa
James Tursa am 15 Jan. 2013
Bearbeitet: James Tursa am 15 Jan. 2013
The use of ~ does not avoid using memory. It simply throws away the corresponding output (somewhat cleaner looking code). It avoids assigning the output to a variable and then manually clearing that variable ... but it does not avoid creating the output in the first place (that would have to take place inside the function itself). I believe the behavior of avoiding the memory usage in the first place for some functions is on the list of future MATLAB enhancements.
Azzi Abdelmalek
Azzi Abdelmalek am 15 Jan. 2013
Bearbeitet: Azzi Abdelmalek am 15 Jan. 2013
When you clear a variable, I think it's avoid using memory
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.)

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 14 Jan. 2013

0 Stimmen

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 Kommentare

Nicholas Bitler
Nicholas Bitler am 24 Nov. 2020
I see tilde everywhere in Matlab, how do you make one with a typical keyboard?
Rik
Rik am 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 am 25 Nov. 2020
And there it is...Thanks Rik

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 14 Jan. 2013

Kommentiert:

am 25 Nov. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by