How do I display a table which has another table as a variable in app designer app in Matlab?

조회 수: 3 (최근 30일)
The code below generates a matlab table which has another table as one of its variables.
test = [1;2;3];
test2 = [5;6;7];
test3 = [9;10;11];
tmp = table(test, test2, test3);
merged = mergevars(tmp,{'test','test2'},'NewVariableName','Combined','MergeAsTable',true);
I want to display a similar table in an app I am building in app designer. I do not find any info how to do that. I would be very grateful for any suggestions.
app.UITable.Data = merged
does generate an empty table in the GUI. Thanks!

답변 (1개)

Pavan Guntha
Pavan Guntha 2021년 10월 22일
Hi Aynur,
You could try placing the following code in the startupFcn of the MATLAB App:
function startupFcn(app)
test = [1;2;3];
test2 = [5;6;7];
test3 = [9;10;11];
tmp = table(test, test2, test3);
merged = mergevars(tmp,{'test','test2'},'NewVariableName','Combined','MergeAsTable',true);
app.UITable.Data = merged;
end
The output of this would be as follows:
If the 'mergevars' function arguments are changed as follows, the output would vary as shown below:
merged = mergevars(tmp,{'test','test2'},'NewVariableName','Combined','MergeAsTable',false);
For more information you could look at the following documentation page which clearly illustrates the required functionality:
Hope this helps!
  댓글 수: 1
Aynur Adanbekova
Aynur Adanbekova 2021년 10월 22일
Hi Pavan, thanks for the response. However, your solution does not include variable names of the sub table. What I want is one header for 2 columns and each of these 2 columns should also have their column names.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by