Azzera filtri
Azzera filtri

What is a handle?

1 visualizzazione (ultimi 30 giorni)
Cheuk Yin Wong
Cheuk Yin Wong il 30 Giu 2022
Commentato: Cheuk Yin Wong il 2 Lug 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.

Risposta accettata

Steven Lord
Steven Lord il 30 Giu 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 Commento
Cheuk Yin Wong
Cheuk Yin Wong il 2 Lug 2022
Thank you very much! This is very clear.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by