write a struct to a ui table

29 ビュー (過去 30 日間)
CoderMinga
CoderMinga 2022 年 9 月 9 日
コメント済み: Ankit 2022 年 9 月 9 日
how to write a struct to a ui table in appdesigner

採用された回答

Ankit
Ankit 2022 年 9 月 9 日
編集済み: Ankit 2022 年 9 月 9 日
You can follow following steps:
S.Name = ["Chang";"Brown";"Ruiz"];
S.Smoker = ["Y";"N";"Y"];
S.SystolicBP = [124;122;130];
S.DiastolicBP = [93;80;92];
fields = fieldnames(S)';
T = struct2table(S); % converting struct to table
app.UITable.Data = T;
app.UITable.ColumnName = fields;
  2 件のコメント
CoderMinga
CoderMinga 2022 年 9 月 9 日
What if an element in a structure is also a structure, how does it show up in the table?
Ankit
Ankit 2022 年 9 月 9 日
What is your use case? In case if structure is also a structure you can use struct2table. In this case you need to first convert it cell (struct2cell) and then to table using cell2table.
But my question is do you want to show the table completely - this is difficult. You can extract the data and display it on table.

サインインしてコメントする。

その他の回答 (1 件)

chrisw23
chrisw23 2022 年 9 月 9 日
structDef = struct("field1",0,"field2",0); % definition
defaultTbl = repmat(struct2table(structDef),10,1); % default empty 10row table
app.UITable.Data = defaultTbl; % copy table to uitable Data property
app.UITable.ColumnName = tbl.Properties.VariableNames; % copy variable names(table) to column names(uitable)
data1 = structDef; % empty struct copy
data1.field1 = 333; % example field data
data1.field2 = 666;
targetRow = 3;
app.UITable.Data(targetRow,:) = struct2table(data1); % write struct data to table row
Another example to show the diffs between table and uitable, because there's only a struct2table() function.

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by