import struct as property in App Designer
10 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
Prajith Chilummula
2019-1-10
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.
Stefan
2019-11-12
编辑:Stefan
2019-11-12
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!