What is the meaning of ~ at fuction?

조회 수: 3 (최근 30일)
Hayeong Oh
Hayeong Oh 2019년 12월 27일
댓글: Hayeong Oh 2020년 1월 3일
at 'Software-Analog Triggered Data Capture' document,
there's startCapture(hObject, ~, hGui) or endDAQ(~, ~, s)
What is the meaning of ~ at fuction?
I don't understand the meaning..
function startCapture(hObject, ~, hGui)
if get(hObject, 'value')
% If button is pressed clear data capture plot
for ii = 1:numel(hGui.CapturePlot)
set(hGui.CapturePlot(ii), 'XData', NaN, 'YData', NaN);
end
end
end
function endDAQ(~, ~, s)
if isvalid(s)
if s.IsRunning
stop(s);
end
end
end
  댓글 수: 2
Bhaskar R
Bhaskar R 2019년 12월 27일
Notthing is passing/getting to function, no need of varible initialization
Hayeong Oh
Hayeong Oh 2019년 12월 27일
Thanks, but I still don't understand..
What is the difference of
endDAQ(~, ~, s) vs. endDAQ(s)
?

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

채택된 답변

Stephen23
Stephen23 2019년 12월 27일
편집: Stephen23 2019년 12월 27일
MATLAB has positional function input and output arguments. This means their purpose is determined entirely by their position when the function is defined and called, not by their names (like in some other programming languages).
It is useful sometimes to ignore particular inputs/outputs, which is what the tilde ~ is for. When defining a function, the tilde ignores a particular input, e.g. using your example the first function has three input arguments, of which only one is used:
function endDAQ(~, ~, s)
% ^ 1st input is ignored
% ^ 2nd input is ignored
% ^ 3rd input is named 's'
vs. your second function which only has one input argument:
function endDAQ(s)
% ^ 1st input is named 's'
Read more:
  댓글 수: 5
Stephen23
Stephen23 2019년 12월 31일
편집: Stephen23 2019년 12월 31일
"What was the variable at the position of first and second?"
All MATLAB callback functions are called with the first two arguments being source and event:
(of course their exact names are not important, as MATLAB has positional arguments).
"I guess that can be (src, event, s) but, why?"
Because those first two input arguments are always supplied when the function is called. The documentation also shows how it is possible to supply the callback with more input arguments, such as by using this syntax:
... 'callback', {@endDAQ, s} ...
which, as the documentation explains, then provides three input arguments when the function is actually called: source, event, and s. So the answer to your question is "by definition".
What the function does with those three arguments is up to the code's author: if they want to ignore some of those input arguments (remember that source and event are always provided), then they can ignore any of those inputs using tildes.
Hayeong Oh
Hayeong Oh 2020년 1월 3일
Thank you again~

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by