import struct as property in App Designer

17 Ansichten (letzte 30 Tage)
ChiPhi85
ChiPhi85 am 6 Jan. 2019
Bearbeitet: Stefan am 12 Nov. 2019
I'd like to load a struct as a .mat file into my app, input values and then save changes. I'd like to import it as a property. I can do it using:
properties (Access = private)
myStruct
end
And then loading it on startup:
function startupFcn(app)
myStruct = load('DemoStruct.mat');
end
This works and I am able to edit and save the struct, but I don't get the option of autocomplete when using app.myStruct. as a way to access the fields in the struct. Is there any way to do this? The only way I can get it to work is by manually typing and this is a pain when there are many fields and indexes at play.

Antworten (2)

Prajith Chilummula
Prajith Chilummula am 10 Jan. 2019
The autocompletion completion uses static analysis, so the variables won’t be completed unless defined in the workspace. During editing, the field names of a struct are not known as they are unavailable in the workspace. Therefore you cannot access the members of the struc variables. But autocomplete can be used while debugging the program. A static code analysis might be misleading also, because fields can be created dynamically also.
  1 Kommentar
ChiPhi85
ChiPhi85 am 10 Jan. 2019
Is there no way to load the struct into the workspace from the app?

Melden Sie sich an, um zu kommentieren.


Stefan
Stefan am 12 Nov. 2019
Bearbeitet: Stefan am 12 Nov. 2019
You could create a class instead of a dynamic struct. For all static properties you will get auto completion.
classdef myStructClass
properties
StaticProperty1
StaticProperty2
DynamicProperties
end
methods
end
end
If you still need some dynamic Properties, you could create a Struct inside the DynamicProperties or similar
properties (Access = private)
myStruct myStructClass;
end
methods
function startupFcn(app)
x = load('DemoStruct.mat')
myStruct = x.myStruct
myStruct.StaticProperty1 = 1; %Auto completion
myStruct.DynamicProperties.I_Need_This_Dynamically = 1; %No Auto completion
end
end

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by