classdef app < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure  matlab.ui.Figure
        UITable   matlab.ui.control.Table
    end

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            % Code that executes after component creation
function startupFcn(app)
    disp("startupFcn called")  % デバッグ用

    % ファイルの絶対パス
    filePath = fullfile(matlabroot,"toolbox","matlab","demos","patients.xls");

    % データ読み込み
    t = readtable(filePath);

    % 必要な列と先頭20行を抽出
    vars = {'Age','Systolic','SelfAssessedHealthStatus','Smoker'};
    t = t(1:20, vars);

    % UITable に設定
    app.UITable.Data = t;
    app.UITable.ColumnName = 'auto';  % 列名を自動設定
    app.UITable.RowName = {};          % 行名は非表示
end
        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 640 480];
            app.UIFigure.Name = 'MATLAB App';

            % Create UITable
            app.UITable = uitable(app.UIFigure);
            app.UITable.ColumnName = {'Column 1'; 'Column 2'; 'Column 3'; 'Column 4'};
            app.UITable.RowName = {};
            app.UITable.Position = [202 149 302 185];

            % 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 = app

            % 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