Appdesigner - Edit the column names during run time

Hello everybody, I am trying to create an app in MATLAB appdesigner. While trying to insert a table with the number of rows and columns as input from the user and initialized using a push button, I am not able to vary the names of the column headers.
If I take 'numbered' option it is adjusting to the input but I am not able to edit the column names.
Please let me know if there is any option for this.
Thank you

6 Comments

Can you share the code you are using to create the table?
Thank you for the response. Sure. Please let me know if any additional information is needed.
methods (Access = private)
% Value changed function: NumberofPropulsorsEditField
function NumberofPropulsorsEditFieldValueChanged(app, event)
NoP = app.NumberofPropulsorsEditField.Value;
end
% Value changed function: NumberofGenSetsEditField
function NumberofGenSetsEditFieldValueChanged(app, event)
NoG= app.NumberofGenSetsEditField.Value;
end
% Value changed function: NumberofConsumersEditField_2
function NumberofConsumersEditField_2ValueChanged(app, event)
NoC = app.NumberofConsumersEditField_2.Value;
end
% Value changed function: NumberofPrimemoversEditField
function NumberofPrimemoversEditFieldValueChanged(app, event)
NoPM = app.NumberofPrimemoversEditField.Value;
end
% Value changed function: NumberofSwitchboardsEditField
function NumberofSwitchboardsEditFieldValueChanged(app, event)
NoS = app.NumberofSwitchboardsEditField.Value;
end
% Button pushed function: InitializeButton
function InitializeButtonPushed(app, event)
%% Produers table
NoG = app.NumberofGenSetsEditField.Value;
NoPM = app.NumberofPrimemoversEditField.Value;
NoR = NoG+NoPM;
app.producers.Data= cell(NoR,3);
app.producers.ColumnEditable = true;
%%consumers table
NoC = app.NumberofConsumersEditField_2.Value;
app.consumers.Data= cell(NoC,2);
app.consumers.ColumnEditable = true;
% %switchboard table
% NoS = app.NumberofSwitchboardsEditField.Value;
% app.connections.Data= cell(NoS,NoR+1);
% app.connections.ColumnEditable = true;
%connections table
NoS = app.NumberofSwitchboardsEditField.Value;
app.connections.Data= cell(NoS+1,NoR+1);
app.connections.ColumnEditable = true;
%%distribution table
NoP = app.NumberofPropulsorsEditField.Value;
app.distribution.Data= cell(NoC+NoP,NoS+1);
app.distribution.ColumnEditable = true;
end
% Create connections
app.connections = uitable(app.UIFigure);
app.connections.ColumnName = {'source'; 'GS1'; 'GS2'; 'PM2'; 'PM2'};
app.connections.RowName = {};
app.connections.ColumnEditable = true;
app.connections.CellEditCallback = createCallbackFcn(app, @connectionsCellEdit, true);
app.connections.Position = [15 220 624 185];
Your edit field callbacks are unnecessary given the code you have shared. The code is duplicated in your pushbutton callback. If you do want to use edit field callbacks to set variable values, you should make the variables app properties. See here: https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html
It looks like you have already added 4 table components to your app canvas (named app.producers, app.consumers, app.connections and distribution). Is that correct?
I do not understand where the 'create connections' code at the bottom is coming from. Is it necessary if you have already added a app.connections Table component to your canvas? I assume you must because you are setting its properties in the push button callback.
It is necessary as the table is initialized using the push button. Is it possible to change the column names during run time or should I just an additional row, where the column names can be added?
It is possible. If it is meant to be part of the pushbutton callback, it needs to be placed before the end statement.
What still isn't clear, though, is where you are going to place it because the first line (app.connections = uitable(app.UIFigure);) overwrites app.connections, removing any information you previously added to it.
This at least works for me, assuming N0G+NoPM = 4
function InitializeButtonPushed(app, event)
%% Produers table
NoG = app.NumberofGenSetsEditField.Value;
NoPM = app.NumberofPrimemoversEditField.Value;
NoR = NoG+NoPM;
app.producers.Data= cell(NoR,3);
app.producers.ColumnEditable = true;
%%consumers table
NoC = app.NumberofConsumersEditField.Value;
app.consumers.Data= cell(NoC,2);
app.consumers.ColumnEditable = true;
% Create connections
app.connections = uitable(app.UIFigure);
app.connections.ColumnName = {'source'; 'GS1'; 'GS2'; 'PM2'; 'PM2'};
app.connections.RowName = {};
app.connections.ColumnEditable = true;
app.connections.CellEditCallback = createCallbackFcn(app, @connectionsCellEdit, true);
app.connections.Position = [15 220 624 185];
%connections table
NoS = app.NumberofSwitchboardsEditField.Value;
app.connections.Data= cell(NoS+1,NoR+1);
%%distribution table
NoP = app.NumberofPropulsorsEditField.Value;
app.distribution.Data= cell(NoC+NoP,NoS+1);
app.distribution.ColumnEditable = true;
end
Thank you for the response. I have tried the above code but I am not able to edit the column names during run-time.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!