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

Jan
Jan 2013년 1월 15일
편집: Jan 2013년 1월 15일
@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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 14일
편집: Azzi Abdelmalek 2013년 1월 14일

1 개 추천

[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

James Tursa
James Tursa 2013년 1월 15일
편집: James Tursa 2013년 1월 15일
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 2013년 1월 15일
편집: Azzi Abdelmalek 2013년 1월 15일
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.)

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2013년 1월 14일

0 개 추천

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

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

질문:

2013년 1월 14일

댓글:

2020년 11월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by