Add row of uitable using UICONTROL

1 次查看(过去 30 天)
How can increase the number of row of the uitable using uicontrol as shown on the image. I have this code but I can't find a way to make it work,
f = figure('Position',[700 200 240 200],'Name','Add Derated Unit','NumberTitle','off');
derated = uitable(f);
derated.ColumnName = {'Rating(MW)','FOR/State Probability'};
derated.RowName = [];
derated.Data = [0 0; 0 0; 0 0];
derated.Position(3) = derated.Extent(3);
derated.Position(4) = derated.Extent(4);
derated.ColumnEditable = [true true];
btn = uicontrol('Style', 'pushbutton', 'String', 'Add Row',...
'Position', [20 100 50 20], 'Callback', @add_row);
function add_row(btn, ~, derated)
data = get(derated, 'data');
data(end+1,:) = 0;
set(derated,'data',data);

采纳的回答

Walter Roberson
Walter Roberson 2017-11-17
btn = uicontrol('Style', 'pushbutton', 'String', 'Add Row',...
'Position', [20 100 50 20], 'Callback', {@add_row, derated});
  3 个评论
Kim Lopez
Kim Lopez 2017-11-17
How can I place the uitable on the topmost part of the figure so that when I add a row of the table, it will be shown it's whole table without scroll bar?
Walter Roberson
Walter Roberson 2017-11-17
I recommend creating a uipanel to put the uitable into. That will make it clearer how you should position your other elements such as your uicontrol and any graphics you might have.
Then when you do create the uitable, set the uipanel as its Parent, and set Units to 'normal', and set Position to [0 0 1 1] so that it takes up the entire uipanel.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by