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 commentaire

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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Data Import and Analysis dans Centre d'aide et File Exchange

Produits

Version

R2016b

Question posée :

le 17 Août 2019

Commenté :

le 19 Août 2019

Community Treasure Hunt

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

Start Hunting!

Translated by