0

I am having a difficult time understanding use of handles

in MATLAB's guide. WHEN TO USE THEM?

For example, this is MATLAB's example how to use MATLAB Guide:

handles.peaks = peaks(35); 
[x, y] = meshgrid(-8:.5:8)
handles.current_data = handles.peaks
surf(handles.current_data)

I guess we are using handles to pass data to the functions.

I'm confused.

dsolimano
  • 8,870
  • 3
  • 48
  • 63
Minimalist
  • 963
  • 12
  • 34

1 Answers1

2

You are not dealing with handles in that example. You have a struct named handles but that's about it (you could have just as well called it chipotle) and you have two lines of code that do absolutely nothing. The only thing there that could give a handle is the function surf which returns a handle for the figure it generated. For example:

chipotle    = peaks(35); 
surf_handle = surf (chipotle);

Things that you can do include selecting this figure again (imagine you have created another figure in the mean time:

new_handle = figure;  # create new figure
sphere;               # draw in the new figure
figure (surf_handle); # select the previous figure

Some functions will take that handle to change things on the figure, for example set or get.

Other examples of handles are file handles:

file_handle = fopen ("splat.dat", "r", "ieee-le");
fread (file_handle, 10, "uint8")
fclose (file_handle)
carandraug
  • 12,938
  • 1
  • 26
  • 38