How to add array of data in new row UITable using same callback function ?

I've added array of data to UITable. i wasn't able to figure out how to added similar array which has different values in a new row without removing the previous added array of data by using same callback function. Any support is appreciated.
% Button pushed function: CreateandLoadSFButton
function CreateandLoadSFButtonPushed(app, event)
%Add to UITable
app.UITable.RowName= 'numbered';
%rwname={Name,Heat Capacity',Cooling Correction,Heating Time,Cooling Time,Voltage,Current,Initial RT,Container Heat Capacity,Liquid Weight};
data={Name,HCap,ydT_2,xH,xC,V,I,Q0,ConHC,W,};
nr=1;
for i=1:10
nr=nr+1;
end
app.UITable.Data(nr,:)=data;
end

 Réponse acceptée

Adam Danz
Adam Danz le 13 Nov 2020
Modifié(e) : Adam Danz le 16 Nov 2020
nr=1;
for i=1:10
nr=nr+1;
end
app.UITable.Data(nr,:)=data;
The section above is from your question. The loop merely sets nr to 11 and does nothing else.
The last line adds/replaces the data to row 11 of the table. If you want to add the data to the next row, use this example:
originaldata = app.UITable.Data;
% Add 1 row of data
originaldata(end+1,:) = data;
app.UITable.Data = originaldataata;
or
app.UITable.Data(end+1,:) = data;

2 commentaires

Thank you Adam Danz.
Then I used globe varible and it works.
hope this will help someone else too.
app.table=app.UITable.Data;
data={Name,HCap,ydT_2,xH,xC,V,I,Q0,ConHC,W};
app.table=[app.table;data];
app.UITable.RowName = 'numbered';
app.UITable.Data=app.table;
By 'global variable' I hope you mean that "table" is declared as a private property using the methods described in the link below rather than declaring the variable as "global".

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by