Adding UITable row data which consists of numbers and strings

4 次查看(过去 30 天)
As the title suggests, I am designing an app in App Designer, which has a table called app.UITable, and I am trying to add rows to the table as added below, then I recieve an error which is also added below. (please help)
Error:
"Error setting property 'Data' of class 'Table':
Values within a cell array must be numeric, logical, or char"
Code:
% Code that executes after component creation
function startupFcn(app)
app.UITable.Data = {
0,0,0,"Consumption (kWh)";
0,0,0,"Consumption (RM)";
0,0,0,"ICPT (-RM0.02 per kWh)";
0,0,0,"ST";
0,0,0,"Current Month Consumption (RM)";
0,0,0,"Current Bill (RM)"
};
end
  1 个评论
Robert
Robert 2022-11-1
Hi,this should do the job. Each line in the cell is a line in the table.
app.UITable.ColumnName = {"Consumption (kWh)";...
"Consumption (RM)";...
"ICPT (-RM0.02 per kWh)";...
"ST" ;...
"Current Month Consumption (RM)";...
"Current Bill (RM)";
}
app.UITable.Data = {1 2 3 4 5 6; 7 9 10 11 12 13;}

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2022-11-1
I'd suggest using cell2table to turn your cell array into a table.
app.UITable.Data = cell2table({0,0,0,"Consumption (kWh)";
0,0,0,"Consumption (RM)";
0,0,0,"ICPT (-RM0.02 per kWh)";
0,0,0,"ST";
0,0,0,"Current Month Consumption (RM)";
0,0,0,"Current Bill (RM)"
})

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by