MATLAB Answers

App Designer, expanding tree using a struct, plotting selected data, edit selected

41 views (last 30 days)
Markus Knoch
Markus Knoch on 5 Apr 2019
Answered: apple on 5 Jul 2019
Hello my name is markus, I´m an currently working as an intern with matlab. While writting my script I´ve stumpled upon the App Designer feature.
I think it has great potential and I would like to learn more about it. Sadly though, beeing a relatively new feature, the documentation, and tutorials are rare and most of them do not cover what I am interested in.
  1. I would like to acess data from a struct that I have created in my matlab script
  2. The struct should appear inside a tree, with all its subcells able to open on "childrens nobs"
  3. The selected data (from the struct), voltage, current and time data should then appear in a plot when they are selected in the tree and after hitting a button
  4. It would be nice to edit certain elements of the struct, which will be saved into the mat file (after hitting a button for example)
I´ve searched quite long for possible examples for such operations but I could not find any. I´m quite familiar with matlab code but the app designer style of obj based programming is very new to me. If anyone could help me solving some of those issues I would very much appreciate it.
I´m using 2018a.

  0 Comments

Sign in to comment.

Answers (3)

Markus Knoch
Markus Knoch on 5 Apr 2019
Im currently working on it. I´ll share my progress.
myStruct = load('data_all.mat');
fNames = fieldnames(myStruct);
for j=1:numel(fieldnames(myStruct))
uitreenode(app.Tree,'Text',string(fNames(j)));
end
This creates the a tree with nodes named after the substruct fieldnames.

  0 Comments

Sign in to comment.


Markus Knoch
Markus Knoch on 5 Apr 2019
I was able to also expand every node with the subsubstructs. Depending on the selected node, the corresponding data from the struct will be displayed at the plots.
myStruct = load('data_all.mat');
fNames1 = fieldnames(myStruct);
for i=1:numel(fieldnames(myStruct))
category(i)=uitreenode(app.Tree,'Text',string(fNames1(i)));
fNames2 = fieldnames(myStruct.(string(fNames1(i))));
for n=1:numel(fieldnames(myStruct.(string(fNames1(i)))))
uitreenode(category(i),'Text',string(fNames2(n)));
end
end
app.myStruct =myStruct;
function TreeSelectionChanged(app, event)
selectedNode = app.Tree.SelectedNodes;
x = app.myStruct.(selectedNode.Text).time;
y1 = app.myStruct.(selectedNode.Text).current;
y2 = app.myStruct.(selectedNode.Text).voltage;
plot(app.UIAxes,x,y2);
app.UIAxes.YLim = [0 22];
plot(app.UIAxes2,x,y1,'r');
app.UIAxes2.YLim = [-2 2];

  0 Comments

Sign in to comment.


apple
apple on 5 Jul 2019
Dear Markus Knoch,
I want to get the whole fields of one hdf5 data and set the data struct to app.Tree, I am not familiar with the nested struct data and the app.Tree . According to your methods, I tried but without success. Could you help me to clear this problem?
% Open the HDF5 File.
FN = 'ATL06_20190223232535_08780212_001_01.h5';
fid = H5F.open (FN, 'H5F_ACC_RDONLY', 'H5P_DEFAULT');
DataInfo = h5info(FN,'/'); % HDF5 data sturct
HDF5 data can be viewed by the following software:
https://www.giss.nasa.gov/tools/panoply/
Thank you very much!
HL

  0 Comments

Sign in to comment.

Products


Release

R2018a