How to load a struct to an uitree in AppDesigner?

8 ビュー (過去 30 日間)
Mark Golberg
Mark Golberg 2021 年 12 月 15 日
回答済み: prabhat kumar sharma 2024 年 1 月 17 日
Hello,
I have an uitree in my AppDesigner GUI.
Is there a fast & convenient way to load a struct into my Tree.
My struct can vary in it's layers ("depth"). It can be:
S.L1.L2 or S.L1.L2.L3. etc...
I've found the following function on FileExchange:
struct2tree (https://www.mathworks.com/matlabcentral/fileexchange/42487-struct2tree).
But after I ran the code:
[m_tree , m_container] = struct2tree(my_struct);
I don't know how to "convert" (or maybe "display" is the more appropriate term) the data stored in m_tree and/or m_container to my uitree in the GUI itself.
I really hope struct2tree could help me. Since I don't know in advance the "depth" of my struct, I don't want start writing any recursive functions "extracting" all the layers from my struct and "building" uitree.
Thanks!!!

回答 (1 件)

prabhat kumar sharma
prabhat kumar sharma 2024 年 1 月 17 日
Hi Mark,
I have downloaded the struct2tree from the file exchange link you provided and tried creating the UITree.
Here are the steps I followed.
  1. Download the struct2Tree from file exchange.
  2. Extract the Zip to the same folder.
  3. Created a new mlapp in the extracted folder (struct2tree).
  4. Added a button to the 'Design View'
function ButtonPushed(app, event)
S = struct('Field1', 'Value1', 'Field2', struct('SubField1', 'SubValue1'));
h = gcf;
struct2tree(S);
end
5. Added a callback function to the button.
6. The UITree created and looks like below screenshot.
I hope it helps!

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by