Adding a class-related function to appdesigner app
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Is there a way, in appdesigner, to create a class-related function, i.e., a function that is local to the app's classdef file, but which is not a class method?
採用された回答
Not that I am aware of or can see an undocumented way -- the closest it allows are private methods that can serve the same purpose albeit that they have the global app struct as a mandatory argument besides any others desired. I don't see any way you can place code past the protected end of the classdef block and since the mlapp files aren't text(*), you can't try to use subterfuge and edit the file in an external editor.
If it's relatively small and tidy, I genrally just go that route; if it is really complex to do a lot of the heavy lifting I usually go ahead and write it as an external m-file and put up with that it is visible outside the app that way. Frequently I find this has some advantages in that can debug outside the app or even make separate command line tools without the need of the GUI. When doing that, the internal properties are dereferenced and passed as individual arguments or part of a struct and don't pass the app struct itself.
Agree, it would be a welcome facility and worthy of an enhancement request.
(*) Interestingly, the MATLAB type command knows enough to present them as if were text which can fool one if looking only with MATLAB tools.
7 件のコメント
I wondered if they were just zipped files -- the file seems to be, but the base content is still not text -- one can see all the header boilerplate text, but not the code so that doesn't work to be able to try to futz on it externally. Not that it would likely work if did, but ...
And, one can export the code to an m-file, but it doesn't have the GUI data and one can't reimport it directly back into appdesigner. And, even though you could add the code in the m-file, when it came to going back you'd again be stuck with not being able to get past the end of the classdef block.
Although I guess if your GUI development was complete so you didn't need to make any further changes to it, then you could forget about appdesigner and just use the m-code by itself -- then you would be able to use the class-related functionality, but it would be essentially a one-way street.
And, even though you could add the code in the m-file, when it came to going back you'd again be stuck with not being able to get past the end of the classdef block.
It wasn't clear to me what "going back" means. I tried to rename the exported mfile to give it a .mlapp extension, but an error was thrown when trying to open that in App Designer.
There is also an m2mlapp converter on the File Exchange,
That did generate an App Designer launchable file, but it discarded the class-related function that I had added below the classdef block.
By "going back" I mean importing the externally-modified m-file code back into App Designer -- there is no Mathworks-provided facility to do that other than by manually pasting the code sections from the m-file into the editable sections inside the App Designer CodeView -- and that won't let you put code outside the classdef block as we already know.
As I tried to say, the only way this would work would be to have all the GUI design done and permanently fixed and then use the exported and modified m-file as the executable code totally outside of App Designer from that point on.(*)
The exported code includes the startup code that creates the GUI components, but it doesn't contain all the meta-data that is in XML included inside the .mlapp file that App Designer uses. You can see their headers if you dump the output of unzipping a .mlapp file; but the code section will be/is still encrypted.
I had not seen the @Eric Delgado tool, clever, obviously he has really delved into the internals at depth. While it appears it does the job of building the sections of an accepatable .mlapp file it is still limited by the design constraints inherent in the App Designer interface which has only the allowable sections and prevents anything outside of those sections to be touched inside the Code View editor.
One would have to be able to figure out how one might actually extend App Designer itself.
(*) Have you tried adding the class-related function in the exported m-file and then executing it directly? It should work, but not inside App Designer, only as standalone code.
Matt J
2026 年 1 月 6 日
Not that I am aware of or can see an undocumented way
Yes, Tech Support just confirmed that that is the case, for now.
dpb
2026 年 1 月 7 日
Did you submit an enhancement request or did they indicate no interest whatsoever in making the extension since the effect can be accomplished by the private method?
Matt J
2026 年 1 月 7 日
I did submit an enhancement request. They were receptive but, as usual, they wouldn't commit up front to its implementation.
dpb
2026 年 1 月 7 日
Roger. Thanks...
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Develop Apps Using App Designer についてさらに検索
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
