Add new row to uitable with push button

In GUIDE, I'm trying to have the user enter in values in two edit boxes. When the button is pushed, the values will populate a table. If the values are changed and the button pushed again, the new values will populate a new row underneath the old values
There have been several previous questions that were solved before (https://www.mathworks.com/matlabcentral/answers/105707-gui-uitable-with-option-to-add-rows-using-push-button, https://www.mathworks.com/matlabcentral/answers/147489-add-a-new-row-in-an-uitable-dynamically-using-a-pushbutton). which either added another row or concatenated the old data with new data.
But I havent been able to get any of them to work. Either the values will start to populate from the 5th row in Attempt 1 or I get an error in "Dimensions of matrices being concatenated are not consistent." in Attempt 2
Var1 = str2double(get(handles.edit1,'string'));
Var2 = str2double(get(handles.edit2,'string'));
%Attempt 1
% % set(handles.uitable1,'data',{Var1 Var2})
% data = get(handles.uitable1, 'data');
% data(end+1,:) = {Var1 Var2};
% set(handles.uitable1,'data',data)
%Attempt 2
% set(handles.uitable1, 'Data',[Var1 Var2]);
old_data=get(handles.uitable1,'Data');
cData = [Var1 Var2];
new_data=[old_data; cData]
set(handles.uitable1, 'Data',new_data);

1 Comment

In this line
new_data=[old_data; cData]
cData must have the same number of columns as old_data.

Sign in to comment.

Answers (0)

Categories

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

Products

Release

R2016b

Asked:

on 17 Aug 2019

Commented:

on 19 Aug 2019

Community Treasure Hunt

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

Start Hunting!