import struct as property in App Designer

12 ビュー (過去 30 日間)
ChiPhi85
ChiPhi85 2019 年 1 月 6 日
編集済み: Stefan 2019 年 11 月 12 日
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.

回答 (2 件)

Prajith Chilummula
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.
  1 件のコメント
ChiPhi85
ChiPhi85 2019 年 1 月 10 日
Is there no way to load the struct into the workspace from the app?

サインインしてコメントする。


Stefan
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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by