What is a handle?

7 visualizaciones (últimos 30 días)
Cheuk Yin Wong
Cheuk Yin Wong el 30 de Jun. de 2022
Comentada: Cheuk Yin Wong el 2 de Jul. de 2022
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.

Respuesta aceptada

Steven Lord
Steven Lord el 30 de Jun. de 2022
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.
  1 comentario
Cheuk Yin Wong
Cheuk Yin Wong el 2 de Jul. de 2022
Thank you very much! This is very clear.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by