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

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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

2019년 8월 17일

댓글:

2019년 8월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by