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 个评论
Adam Danz
2019-8-19
In this line
new_data=[old_data; cData]
cData must have the same number of columns as old_data.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!