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
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 ExchangeData Import and Analysis についてさらに検索

製品

リリース

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