banner



Using Ui Table With App Designer

You can use the table component.

My example is based on the following example, which displays MATLAB table in a uitable (user interface table component).

  • You can start by adding a table to the application main figure in App Designer design view.
    You can also add the update button in design view.
  • Add a private property to the app class for storing the table data (I named it T):

                  properties (Access = private)     T % Table end                          
  • You may initialize table T in the startupFcn like in the following example:

                  % Code that executes after component creation function startupFcn(app)     LastName = {'Smith'; 'Johnson'; 'Williams'; 'Jones'; 'Brown'};     Age = [38; 43; 38; 40; 49];     Height = [71; 69; 64; 67; 64];     Weight = [176; 163; 131; 133; 119];     app.T = table(Age, Height, Weight, 'RowNames', LastName); end                          
  • In the button pushed callback, you can update the table like in the following example:

                  % Button pushed function: UpdateButton function UpdateButtonPushed(app, event)     app.UITable.Data = app.T{:,:};     app.UITable.ColumnName = app.T.Properties.VariableNames;     app.UITable.RowName = app.T.Properties.RowNames; end                          

Here is how the user interface looks like (after pressing update button):

enter image description here


Here is the complete code (include automatically generated code):

          classdef app1 < matlab.apps.AppBase      % Properties that correspond to app components     properties (Access = public)         UIFigure      matlab.ui.Figure         UITable       matlab.ui.control.Table         UpdateButton  matlab.ui.control.Button     end       properties (Access = public)         children = app1.empty % Description     end      properties (Access = private)         T % Table     end       % Callbacks that handle component events     methods (Access = private)          % Code that executes after component creation         function startupFcn(app)             LastName = {'Smith'; 'Johnson'; 'Williams'; 'Jones'; 'Brown'};             Age = [38; 43; 38; 40; 49];             Height = [71; 69; 64; 67; 64];             Weight = [176; 163; 131; 133; 119];             app.T = table(Age, Height, Weight, 'RowNames', LastName);         end          % Button pushed function: UpdateButton         function UpdateButtonPushed(app, event)             app.UITable.Data = app.T{:,:};             app.UITable.ColumnName = app.T.Properties.VariableNames;             app.UITable.RowName = app.T.Properties.RowNames;         end     end      % Component initialization     methods (Access = private)          % Create UIFigure and components         function createComponents(app)              % Create UIFigure and hide until all components are created             app.UIFigure = uifigure('Visible', 'off');             app.UIFigure.Position = [100 100 322 233];             app.UIFigure.Name = 'UI Figure';              % Create UITable             app.UITable = uitable(app.UIFigure);             app.UITable.ColumnName = {'Column 1'; 'Column 2'; 'Column 3'; 'Column 4'};             app.UITable.RowName = {};             app.UITable.Position = [36 57 251 163];              % Create UpdateButton             app.UpdateButton = uibutton(app.UIFigure, 'push');             app.UpdateButton.ButtonPushedFcn = createCallbackFcn(app, @UpdateButtonPushed, true);             app.UpdateButton.Position = [36 14 100 22];             app.UpdateButton.Text = 'Update';              % Show the figure after all components are created             app.UIFigure.Visible = 'on';         end     end      % App creation and deletion     methods (Access = public)          % Construct app         function app = app1              % Create UIFigure and components             createComponents(app)              % Register the app with App Designer             registerApp(app, app.UIFigure)              % Execute the startup function             runStartupFcn(app, @startupFcn)              if nargout == 0                 clear app             end         end          % Code that executes before app deletion         function delete(app)              % Delete UIFigure when app is deleted             delete(app.UIFigure)         end     end end                  

You can copy an paste the code to app1.m file, just to see how it works (without using App Designer).

Using Ui Table With App Designer

Source: https://stackoverflow.com/questions/59720558/how-to-display-a-matlab-table-in-a-matlab-app

Posted by: mcconnellusithed.blogspot.com

0 Response to "Using Ui Table With App Designer"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel