【问题标题】:UITable Matlab - Accessing specific cellUITable Matlab - 访问特定单元格
【发布时间】:2015-04-08 01:12:24
【问题描述】:

我正在使用此代码获取所选单元格的行索引:

row = eventdata.Indices(1);

我还可以通过将 1 更改为 2 来获取列索引。但我希望能够在该特定行中获取我想要的任何单元格的内容,而无需用户实际单击该特定单元格,而是在任何地方在那一排。假设我想从第一列中获取数据,在我的例子中代表 ID。

在伪代码中它看起来像:

x = getRowOfSelectedCell
field = Indices(x,1);

假设选定的行是 5。变量字段将由第 5 行第一列中的单元格的值组成。

任何想法如何进行?

【问题讨论】:

    标签: matlab uitableview indices


    【解决方案1】:

    怎么样:

    function ScriptTest
    
    d = rand(10,7);
    t = uitable('Data', d,  'Units', 'norm', 'Position', [0,0,1,1]);
    
    RequiredColumnIndex = 5;
    set( t, 'CellSelectionCallback', {@TableSelectionCB, RequiredColumnIndex});
    
    function TableSelectionCB(hTable, eventdata, RequiredColumnIndex)
        rowIndex = eventdata.Indices(1);
        TableData = get(hTable,'Data');
    
        field = TableData(rowIndex, RequiredColumnIndex);
        fprintf(' Value in cell [Row %d /Col %d ] is %f \n',  rowIndex, RequiredColumnIndex, field);
    end
    
    end
    

    在这里,我决定检索第 5 列中的数据(按照您的建议)并在命令窗口中打印相应的单元格值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多