MATLAB GUI: Is it possible to run '' generate code'' (from a figure) automatically(without clicking the option)?

2 ビュー (過去 30 日間)
Hi all, I'm working on a GUI which can generate figures from simulation results. I would like to know if there is a function or command that runs ''generate code'' (from a figure) automatically without clicking the option in menu bar? Because I want to record all the user changes that the user has made in the figure, e.g. the user may drag the legend to another position. And among all features or commands of MATLAB, I think ''generate code'' may be the only one that helps(or do you have any suggestions?) But it's quite troublesome if I click generate code every time and assign input values to it when I call the generated .m file. Therefore I want to achieve these series actions in callback function automatically(by clicking a pushbutton), yet I'm not sure if it's possible.
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 1 月 14 日
How do you need to process the recorded changes afterwards?
dyyyyyl
dyyyyyl 2016 年 1 月 15 日
Afterwards, when I click a pushbutton like ''load setup'', all the signals saved in ''setup file'' will be automatically selected and plotted with the same style, that I modified earlier, including the changed position of legends etc. So that I don't need to drag the legend to an appropriate place every time :)

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

採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 15 日
If you are using R2014b or later then after you have moved the legend object during your design phase, you can request the legend object Position property; then in your later code after you generate a legend object you can set it to have that Position.
If you are using R2014a or earlier then legend are axes within the parent figure; you can get() the axes Position property, save it, use it later on the generated legend. Be sure to return the legend handle from the legend call as the handle visibility is set to callback which makes the object more difficult to find if you do not know the handle.
  6 件のコメント
dyyyyyl
dyyyyyl 2016 年 1 月 17 日
You mean just record the postion matrix, like [0.63 x x x]? Yet I would like to share the legend object(reference), so when I change its position, I can recall it in another callback function and therefore get its new position.
Walter Roberson
Walter Roberson 2016 年 1 月 17 日
You cannot recall a deleted object.
Are you updating handles.legendf with the legend object before you guidata(hObject, handles) to save the object reference?
Note: when you save an object such as a legend, you are saving a reference to the actual graphics object that MATLAB uses to draw with; you are not just saving a copy of the data structures that were used for the object, such as information about its position or markers or colors or whatever. When you save a graphics object, you are not just saving a template. Therefore if you delete a graphics object, either directly or because the axes or figure gets cleared, you cannot "recall" the graphics object to use as information about how to draw another similar copy.
It is possible to set an object visibility to off so it disappears from view, and latter set it visible again, provided that it has not been deleted in the meantime (so you want to have it survive the clearing of its parent axes or figure then move it to a different axes or figure for safe-keeping, and move it back when you want it.)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by