【问题标题】:Handles in Matlab GuideMatlab 指南中的句柄
【发布时间】:2012-09-01 15:11:01
【问题描述】:

我很难理解句柄的使用

在 MATLAB 的指南中。什么时候使用它们?

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

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

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

我很困惑。

【问题讨论】:

    标签: matlab matlab-guide


    【解决方案1】:

    在该示例中,您没有处理句柄。您有一个名为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-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 1970-01-01
      相关资源
      最近更新 更多