> ageString = datestr(ageInDays, 'HH:MM:SS.FFF') > ageDuration = duration(ageInDays*24,0,0) ![]() > ageString = datestr (ageInDays, 'HH:MM:SS.FFF' ) ![]() > ageDuration = duration (ageInDays* 24, 0, 0 ) However, a “cleaner” approach seems to be to create new read-only properties for the figure’s CreationTime and Age:įirst, create a small Matlab function as follows, that attaches the CreationTime property to a figure: The simple answer would be to use setappdata with the creation date whenever we create a figure. Secondly, I happened to run into a perfect usage example a short while ago that called for this solution: a StackExchange user asked whether it is possible to tell a GUI figure’s age, in other words the elapsed time since the figure was created. Well, first, because my experience has been that this little tidbit is fairly unknown by Matlab developers. Then again, I’d have less to blog about in that case…Īnyway, why am I rehashing old news that I have already reported a few years ago? So much frustration could have been solved if MathWorks would simply remove the Sealed class meta-property from its classes. In other words, the new properties will only be added to the handles that we specifically request, and not to any others.Īll this is important, because for some unexplained reason that escapes my understanding, MathWorks chose to seal its classes, thus preventing users to extend them with sub-classes that contain the new properties. The bottom line is that we can dynamically add custom properties in run-time to any HG object, without affecting any other object. What is still NOT documented, as far as I could tell, is that all of Matlab’s builtin handle graphics objects indirectly inherit the dynamicprops class, which allows this. As I wrote in that post, in HG2 (R2014b onward), we can use the fully-documented addprop function to add new custom properties (and methods) to such objects. While there was never a fully-documented way to do this, most users simply attached such properties as fields in the UserData property or the object’s ApplicationData property (accessible via the documented setappdata/ getappdata functions).Īn undocumented way to attach actual new user-defined properties to objects such as GUI handles or Java references has historically (in HG1, up to R2014a) been to use the undocumented schema.prop function, as I explained here. ![]() For various purposes, it is sometimes useful to attach custom user-defined properties to such objects. In addition, you can leave the handles hidden and use findall, which requires you to know some of the properties of the object you're looking for.Matlab objects have numerous built-in properties (some of them publicly-accessible/documented and others not, but that’s a different story). The above could also be done with dot notation for property access like so: delete(lg.UIContextMenu.Children(4)) > delete(hItems(4)) % Delete the fourth item > hItems = get(hMenu, 'Children') % Get the menu item handles Then you can just do the following: > hMenu = get(lg, 'UIContextMenu') % Get the context menu handleĬhildren: % This would be empty if handles were still hidden The first thing you'll need to do is set the ShowHiddenHandles property of the root object to 'on', which will make hidden handles discoverable.
0 Comments
Leave a Reply. |