MATLAB Answers

How to create Favorites by code / Command Window?

44 ビュー (過去 30 日間)
sfreeman 2018 年 7 月 24 日
コメント済み: Linzu 2020 年 2 月 20 日
I was used to create the shortcuts in R2017b and older via code:
jUtils = com.mathworks.mlwidgets.shortcuts.ShortcutUtils;
jUtils.addShortcutToBottom(sName,sCcallback,sIcon,sCategory, 'true');
Of course it does not work to create the new "favorites", but I would like to do so.
I have found the com.mathworks.mlwidgets.favoritecommands.FavoriteCommandProperties class with get/set methods, but if I got it right, I would Need some stuff from com.mathworks.mlwidgets.favoritecommands.FavoriteCommandActions, which has not constructor.
Any ideas out there, how to create favorites and their categories by code?

  0 件のコメント

Sign in to comment.


Martin Lechner
Martin Lechner 2018 年 11 月 23 日
For managing the favorites use the FavoriteCommands class. The available methods can be seen by using methodsview:
fc = com.mathworks.mlwidgets.favoritecommands.FavoriteCommands.getInstance()
methodsview(fc) % to show all available methods with their parameters
Before you add a new favorite command with the FavoriteCommands class you must create your FavoriteCommandProperties object, for example like:
newFavoriteCommand = com.mathworks.mlwidgets.favoritecommands.FavoriteCommandProperties()
newFavoriteCommand.setLabel("Programatically added Favorite")
newFavoriteCommand.setCategoryLabel("MY CREATED CATEGORY") % use always upper case letters, otherwise I got problems to add furterh favorits
newFavoriteCommand.setCode("disp('Hallo World! This greate command was added programatically, by com.mathworks.mlwidgets.favoritecommands.FavoriteCommands.getInstance()')")
% add the command to the favorite commands (the category is automatically created if it doesn't exist)

  8 件のコメント

表示 5 件の古いコメント
Linzu 2019 年 12 月 4 日
Hello Martin Lechner. Thank you for solution. Besides I have anothor question for help.
I set icon with command like
but does not show. Can you help me? Thank you.
Best wishes.
Martin Lechner
Martin Lechner 2019 年 12 月 4 日
You have to set the folder of the icon and the icon name seperatly.
newFavoriteCommand.setIconPath('C:\xxxx') % only the icon's folder!
newFavoriteCommand.setIconName('xxx.png') % the icon's file name with the extension
Linzu 2020 年 2 月 20 日
It works fine!
Thank you very much

Sign in to comment.

その他の回答 (0 件)




Translated by