0

我很难理解手柄的使用

在 MATLAB 的指南中。何时使用它们?

例如,这是 MATLAB 的示例如何使用 MATLAB 指南:

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

我想我们正在使用句柄将数据传递给函数。

我很困惑。

4

1 回答 1

2

在该示例中,您没有处理句柄。您有一个名为handles 的结构,但仅此而已(您也可以将其称为chipotle),并且您有两行代码完全什么都不做。唯一可以提供句柄的是函数 surf ,它返回它生成的图形的句柄。例如:

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

您可以做的事情包括再次选择此图形(假设您同时创建了另一个图形:

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

一些函数将使用该句柄来更改图形上的内容,例如setget

句柄的其他示例是文件句柄:

file_handle = fopen ("splat.dat", "r", "ieee-le");
fread (file_handle, 10, "uint8")
fclose (file_handle)
于 2012-09-01T15:30:52.017 回答