MATLAB: How to index tables in a struct? (to call each field from App Designer)

app designerMATLABr2019a

Hello,
I'm facing a problem while coding on App Designer. I have saved a workspace made of diferent tables.
The tables are created this way:
a{1}=
a{2}=
a{3}=
etc…
I created it this way to be able to call them in the code on App Designer (in which I have imported the workspace with the command "load") in a loop, for example:
app.data = load('workspace.mat'); % command used to load the workspace in App Designer
for i = 1 : numel(fieldnames(app.data))
disp(app.data.a(i)) %here is the problem
end
Matlab send me an error when executing this or any combination of app.data.a with (i) or {i} …
A "a" field of cell type is beeing created when running the workspace but this same "a" clas isn't loaded with the rest of the fields when importing in App Designer.
Thanking you in advance for your help 🙂

Best Answer

You need to loop over the fieldnames:
app.data = load('workspace.mat');
C = fieldnames(app.data);
for k = 1:numel(C)
T = app.data.(C{k});
... do whatever with table T
end
Read this: