What is a handle?

7 次查看(过去 30 天)
I always see the word 'handle' in the matlab community but I don't quite understand what is it even I search it online. I am an absolute begineer of matlab, can anyone please give me a simple explaination or direct me to the right resource. Thank you.

采纳的回答

Steven Lord
Steven Lord 2022-6-30
What's the context in which you see that term? There are at least three different meanings for that term, though two of them are somewhat related.
  • Handle as related to graphics? Start with this documentation page. Graphics handles let you manipulate graphics objects on screen; for example if I have a line's handle I can change its Color property and so change what color it is.
h = plot(1:10, 1:10); % h is the line's handle. By default it is blue.
figure % Let's make a second line so you can see the difference when I change its color
h2 = plot(1:10, 1:10);
h2.Color = 'r'; % Let's make this line red
  • Handle in terms of object-oriented programming? See here, though this is often thought of as an advanced skill for MATLAB programming. Graphics handles are handle objects, though not all handle objects are graphics objects.
  • Handle as related to evaluating a function, like with an ODE solver or optimization routine? Those are function handles, which are useful in passing a "reference" to function A into function B so that function B can call function A with input arguments of its choice.
f = @sin;
Find a zero of the function y = sin(x). Start looking at 1. fzero will call f with points of its choosing as it looks for a solution.
x = fzero(f, 1)
x = 1.5485e-24
To check, evaluate the function handle yourself at the point fzero found.
shouldBeCloseTo0 = f(x)
shouldBeCloseTo0 = 1.5485e-24
That's pretty close to 0.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by