classdef app2 < matlab.apps.AppBase
properties (Access = public)
UIFigure matlab.ui.Figure
Panel matlab.ui.container.Panel
addrowButton matlab.ui.control.Button
UITable matlab.ui.control.Table
addcolumnButton matlab.ui.control.Button
editnamecolumnButton matlab.ui.control.Button
end
properties (Access = private)
Data_temp=[]
UI_ColumnOldName;
UI_ColumnNewName;
end
methods (Access = private)
function name_col(app,new_name)
app.UITable.ColumnName{(app.Data_temp(2))}=char(new_name.Value);
end
function SetSelectionName(app)
if isgraphics(app.UI_ColumnOldName)
app.UI_ColumnOldName.Value = app.UITable.ColumnName{(app.Data_temp(2))};
app.UI_ColumnNewName.Value = app.UI_ColumnOldName.Value;
end
end
end
methods (Access = private)
function startupFcn(app)
app.UITable.Data=cell(10,3);
app.UITable.ColumnEditable=true;
app.UITable.ColumnName ={'A','B','C'};
end
function UITableCellSelection(app, event)
app.Data_temp=event.Indices;
app.SetSelectionName;
end
function addcolumn_ButtonPushed(app, ~)
app.UITable.Data(:,end+1)={''};
column_name=char(inputdlg('column name'));
app.UITable.ColumnName{end+1}=column_name;
end
function addrow_ButtonPushed(app, ~)
app.UITable.Data(end+1,:)={''};
end
function editnamecolumn_ButtonPushed(app, ~)
if isempty(app.Data_temp)
warndlg('select a cell below the desidered column');
else
UI_Column=uifigure('Name','Column Name','Position',[100 100 429 276]);
app.UI_ColumnOldName=uitextarea(UI_Column,'Position',[100 140 100 22]);
app.UI_ColumnNewName=uitextarea(UI_Column,'Position',[220 140 100 22]);
UI_label=uilabel(UI_Column,'Text','new column name','Position',[220 165 100 22]);
UI_label_2=uilabel(UI_Column,'Text','old column name','Position',[100 165 100 22]);
UI_save=uibutton(UI_Column,'Text','Save','Position',[220 100 100 22],'ButtonPushedFcn',@(UI_save,event) name_col(app,new_name));
app.SetSelectionName;
end
end
end
methods (Access = private)
function createComponents(app)
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 697 560];
app.UIFigure.Name = 'UI Figure';
app.Panel = uipanel(app.UIFigure);
app.Panel.Title = 'Panel';
app.Panel.Position = [114 113 495 382];
app.addrowButton = uibutton(app.Panel, 'push');
app.addrowButton.ButtonPushedFcn = createCallbackFcn(app, @addrow_ButtonPushed, true);
app.addrowButton.Position = [23 271 100 22];
app.addrowButton.Text = 'add row';
app.UITable = uitable(app.Panel);
app.UITable.ColumnName = {'Column 1'; 'Column 2'};
app.UITable.RowName = {};
app.UITable.CellSelectionCallback = createCallbackFcn(app, @UITableCellSelection, true);
app.UITable.Position = [152 108 302 185];
app.addcolumnButton = uibutton(app.Panel, 'push');
app.addcolumnButton.ButtonPushedFcn = createCallbackFcn(app, @addcolumn_ButtonPushed, true);
app.addcolumnButton.Position = [24 230 100 22];
app.addcolumnButton.Text = 'add column';
app.editnamecolumnButton = uibutton(app.Panel, 'push');
app.editnamecolumnButton.ButtonPushedFcn = createCallbackFcn(app, @editnamecolumn_ButtonPushed, true);
app.editnamecolumnButton.Position = [19 189 112 22];
app.editnamecolumnButton.Text = 'edit name column';
end
end
methods (Access = public)
function app = app2
createComponents(app)
registerApp(app, app.UIFigure)
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
function delete(app)
delete(app.UIFigure)
end
end
end
Best Answer