matlabmatlab-app-designer

Link editable field to a certain cell in table figure in MATLAB app designer


I am building an application in MATLAB app designer (2019b), and I am trying to link two blank fields to a table that has only two columns, such that the first field should show the first value (in the first column) in the table and the other should show the last value in the first column in the table.

Example

table:

9     2
3     4
5     6
blank field_1: 9
blank field_2: 5

I am a C++ person, so whenever I am developing, for instance in SFML, I just have one event loop that captures and updates everything - no matter where I press on the window, but, in MATLAB, whenever I press a button - I need to build a separate callback function. Here, I am not calling back anything - I just need to update the value.

Anyone, please help?

Thank you


Solution

  • Here's an example which illustrates how you can achieve the behavior you want. In the below example, I am creating a uitable in the App startup, and I am defining a callback which updates the table as required when the cells are modified.

    function startupFcn(app)
        vars = {9,2;3,4;5,6;'blank _field_1:', '';'blank field_2:', ''};
        t = uitable(app.UIFigure,'Data',vars);
        t.ColumnEditable = true;
        t.DisplayDataChangedFcn = @updateTable;
    
        function updateTable(src,~)
            src.Data(end-1:end,2:end) = [src.Data(1,1) src.Data(end-2,1)].';
        end
    end