0

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

Wolfie
  • 27,562
  • 7
  • 28
  • 55

1 Answers1

0

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
Paolo
  • 21,270
  • 6
  • 38
  • 69
  • Thank you so much for replying Sorry if my question is weird, but is the start-up function a normal private function that I define and will this work whenever I update the table? – ProgrammingGuy May 12 '20 at 15:01
  • I have no idea what your App implementation looks like. I showed you what the implementation could look like. You should create a function in your app which essentially does what my `updateTable` does here. – Paolo May 12 '20 at 15:03