- Enclose with " for exact match e.g., "uitable report"
- Advanced on-site Matlab training, amazing value - additional info
- Some performance-tuning tips
- Sliders in Matlab GUI
- Persisting transparent colors in HG2
- Undocumented HG2 graphics events
- copyobj behavior change in HG2
- General-use object copy
- Auto-completion widget
- Undocumented view transformation matrix
- Handle object as default class property value
- Plot legend title
- Using Infiniband with Matlab Parallel Computing Toolbox
- Frameless (undecorated) figure windows
- Transparent legend
- Customizing Matlab uipanels
- Simulink Data Dictionary
- Desktop (35)
- Figure window (36)
- Guest bloggers (47)
- GUI (122)
- Handle graphics (66)
- Hidden property (34)
- Icons (7)
- Java (140)
- Listeners (18)
- Memory (14)
- Mex (9)
- Presumed future risk (295)
- Semi-documented feature (7)
- Semi-documented function (31)
- Stock Matlab function (115)
- Toolbox (4)
- UI controls (41)
- Uncategorized (10)
- Undocumented feature (148)
- Undocumented function (30)
TagsActiveX Callbacks COM Compiler Desktop Donn Shull Editor FindJObj GUI GUIDE Handle graphics HG2 Hidden property HTML Icons Internal component Java JavaFrame JIDE JMI keyboard Listener Malcolm Lidierth MCOS Memory Menubar Mex Optical illusion Performance Profiler Pure Matlab schema schema.class schema.prop scribe Semi-documented function Toolbar uicontrol UIInspect uitable uitools uiundo Undocumented feature Undocumented function Undocumented property
- Karai (2 days 6 hours ago): Hi Yair, Is it possible to download Java source code for ExampleWindow? I would be very grateful if you could send me a link. Kind regards
- Vidya (3 days 0 hours ago): Hello Yair, I started using the Java sliders in Matlab yesterday and they work great (thanks for the texbook as well as the tutorials)! I do not have much experience with Java though,...
- Yair Altman (5 days 5 hours ago): You need to set the callbacks to update the text dynamically, of course. If you’d like me to help you debug your specific issue, contact me by email for a short consulting.
- Yair Altman (5 days 5 hours ago): http://undocumentedmatlab.com/ blog/javacomponent#comment-802 47
- Christina (5 days 5 hours ago): How do you change the tick labels? I’m trying to use the JSlider for a time range and so I want the labels to be datestr(x,13) output of the times. Can’t seem to...
- CH (5 days 7 hours ago): If I use the following line set(handles.status,'String',cw Text); in the status box of my GUI, it does not show the updated outputs dynamically. I could see only first several lines...
- Yair Altman (5 days 7 hours ago): @CH – What exactly are you trying to set hh to?! what’s wrong with setting your status box directly to cwText?
- CH (5 days 8 hours ago): Hi Yair, I have read your posting and answer for the command window output catching. I tried to use your method to send the command window outputs to the my own GUI. However, it...
- Fredrik (8 days 7 hours ago): Thanks, will try. Fredrik
- Yair Altman (8 days 8 hours ago): @Fredrik – you are using an old version of export_fig. Download and install the latest version.
- Fredrik (8 days 9 hours ago): Hi, I had great hopes to create a PDF file out of my uipanel using export_fig but when I pass the panel handle like this export_fig('myFileName.pdf','- pdf',myUIpanelHandle) I get...
- Cristiano (10 days 20 hours ago): Hello, Yair. The methods you mention is useful，however，when I zoomed the window I found the Icon was overlapped by the String. Finally，If I let a dialog or form have a FIXED...
- Jeff (11 days 5 hours ago): Hi Yair, Thanks for the post. You can also do a lot to customize the appearance of each LaF by using the public ‘setTheme’ method, which accepts a java.util.Properties...
- Yair Altman (11 days 12 hours ago): @Brad – thanks for your kind words, and for your very rich coffee – what a nice way to wake up in the morning The program’s code size was not small (close...
- Brad Stiritz (11 days 22 hours ago): Hi Yair, thanks for the great blog post! Fantastic troubleshooting example, well-done I just finished reading Code Complete 2 (highly recommended!), which discusses among...
Today’s post is about performance. My goal is to show that contrary to widespread perception, Matlab is not inherently too slow to be used for real-life programs. In fact, by taking a small amount of time (compared to the overall dev time), Matlab programs can be accelerated by a large factor. I wish to demonstrate this claim with work that I recently completed for the Crustal Dynamics research group at Harvard University. They have created interactive Matlab GUIs for earthquake hazard, visualizing deformation and motion at plate boundary zones, recorded as GPS velocities:
These GUIs served them well for several years. But when they recently tried to analyze larger problems that involved far more data, it was getting so slow that it limited their ability to interrogate the GUI results effectively and do productive science (take a look at all the data points around New Zealand in the screenshot above). This is when I stepped in to help.
One of my consulting clients asked me last week if I knew an easy way to integrate a range (dual-knob) slider control in Matlab GUI. Today’s post is an expansion of the answer I provided him, which I though might interest other Matlab users.
- Matlab vs. Java sliders
- Using JSlider
- Range (dual-knob) sliders
- AppDesigner – Matlab’s new GUI
- Conclusions and some personal musings
Matlab vs. Java sliders
As funny as it may sound, Matlab’s so-called “slider” control (
uicontrol('Style','slider')) is actually implemented as a scroll-bar, rather than the more natural JSlider. I believe that this is due to a design decision that occurred sometime in the 1990′s (sliders were not as prevalent then as they are nowadays). This was never corrected, probably for backward-compatibility reasons. So to this day, Matlab’s so-called “slider” is actually a scroll-bar, and we do not [yet] have a real slider control in standard Matlab, apparently since the ‘slider’ uicontrol style is already in use. Spoiler alert: this will change soon — keep reading.
It gets worse: for some reason Matlab’s implementation of the so-called “slider” uses a Windows95 look-and-feel that makes the control look antique in today’s GUI standards. Using Java Swing’s standard JScrollBar control would at least have made it appear more consistent with the other Matlab controls, which are all based more closely on Java Swing:
% Standard Matlab "slider" uicontrol('style','slider', 'position',[10,10,200,20]); % Standard Java JScrollBar jScrollbar = javax.swing.JScrollBar; jScrollbar.setOrientation(jScrollbar.HORIZONTAL); javacomponent(jScrollbar,[10,40,200,20]); % Standard Java JSlider (20px high if no ticks/labels, otherwise use 45px) jSlider = javax.swing.JSlider; javacomponent(jSlider,[10,70,200,45]);
I advise users of the current Matlab GUI to use
JSlider, rather than Matlab’s standard “slider” uicontrol. The rest of today’s post will discuss the
Several months ago, I showed how we can set semi- and fully-transparent colors in HG2 (Matlab’s new graphics engine, starting in R2014b) for multiple graphic objects, including plot lines, plot markers, and area charts:
hLine = plot([0,150], [-0.5,0.5], 'r'); box off; hold on; ydata = sin(0:0.1:15); hArea = area(ydata); drawnow; pause(0.05); % this is important! hArea.Face.ColorType = 'truecoloralpha'; hArea.Face.ColorData(4) = 40; % 40/255 = 0.16 opacity = 84% transparent
Unfortunately, these settings are automatically overridden by Matlab when the figure is printed, saved, or exported:
% These commands result in an opaque (non-transparent) plot print(gcf); saveas(gcf, 'plot.png');
R2014b brought a refreshing new graphics engine and appearance, internally called HG2 (the official marketing name is long and impossible to remember, and certainly not as catchy). I’ve already posted a series of articles about HG2. Today I wish to discuss an undocumented aspect of HG2 that I’ve encountered several times over the past months, and most recently today. The problem is that while in the previous HG1 system (R2014a and earlier) we could add property-change listener callbacks to practically any graphics object, this is no longer true for HG2. Many graphics properties, that are calculated on-the-fly based on other property values, cannot be listened-to, and so we cannot attach callbacks that trigger when their values change.
Property-change listeners in HG1
Take for example my post about setting axes tick labels format from 3 years ago: the idea there was to attach a Matlab callback function to the
PropertyPostSet event of the XTick, YTick and/or ZTick properties, so that when they change their values (upon zoom/pan/resize), the corresponding tick-labels would be reformatted based on the user-specified format:
As a followup to last-week’s post on class-object and generic data copies, I would like to welcome back guest blogger Robert Cumming, who developed a commercial Matlab GUI framework. Today, Robert will highlight a behavior change of Matlab’s copyobj function in HG2.
One of the latest features that was introduced to the GUI Toolbox was the ability to undock or copy panels, that would be displayed in a standalone figure window, but remain connected to the underlying class object:
These panel copies had to remain fully functional, including all children and callbacks, and they needed to retain all connections back to the source data. In the example above I have altered the plot to show that it’s an actual copy of the data, but has separate behavior from the original panel.
To simply undock a uipanel to a new figure, we can simply re parent it by updating its Parent property to the new figure handle. To make a copy we need to utilize the copyobj function, rather than re-parenting. copyobj can be used to make a copy of all graphic objects that are “grouped” under a common parent, placing their copy in a new parent. In HG2 (R2014b onwards) the default operation of copyobj has changed.
When using Matlab objects, either a Matlab class (MCOS) or any other (e.g., Java, COM, C# etc.), it is often useful to create a copy of the original object, complete with all internal property values. This enables modification of the new copy without affecting the original object. This is not important for MCOS value-class objects, since value objects use the COW (Copy-on-Write/Update, a.k.a. Lazy Copy) and this is handled automatically by the Matlab interpreter when it detects that a change is made to the copy reference. However, it is very important for handle objects, where modifying any property of the copied object also modifies the original object.
Most OOP languages include some sort of a copy constructor, which enables programmers to duplicate a handle/reference object, internal properties included, such that it becomes entirely separate from the original object. Unfortunately, Matlab did not include such a copy constructor until R2011a (matlab.mixin.Copyable.copy()).
On Matlab R2010b and older, as well as on newer releases, we do not have a readily-available solution for handle object copy. Until now, that is.
Do you ever get a feeling when designing a Matlab GUI, that existing components/controls are simply not enough to achieve the desired functionality/appearance?
Such a case happened to me, when a consulting client asked me to integrate an auto-completion widget in a GUI that I designed for them. The idea was simple enough: the user selects a class of financial assets from a drop-down, then one or more actual financial securities from a dynamically-populated drop-down (based on the asset class), then the date range and analysis function, and finally the results are plotted in the main panel. The idea was for Matlab to automatically auto-complete the financial instruments matching the entered text, as it is being typed, similarly to other standard auto-completion widgets (e.g., Google’s search box), including the use of wildcards and regular expressions:
Note that in this particular case, I use the term “auto-completion” loosely. The correct term should actually be “auto-winnowing” or “auto-filtering”. Auto-completion is usually reserved for the case of the user-entered text being automatically completed as they type, whereas auto-winnowing only updates the drop-down options on-the-fly. These two functionalities are often correlated, and today’s article will discuss both.
Everyone knows Matlab’s view function, right? You know, the function that can set a 3D plot to the proper orientation angles and/or return the current plot’s azimuth/elevation angles. I’ve used it numerous times myself in the past two decades. It’s one of Matlab’s earliest functions, dating back to at least 1984. Still, as often as I’ve used it, it was not until I came across Bruce Elliott’s post on CSSM last week that I realized that this seamingly-innocent stock Matlab function holds a few interesting secrets.
view()’s transformation matrix output
First, while view‘s 2-output syntax (
[az,el]=view()) is well known and documented, there is also a single-output syntax (
T=view()) that is neither. To be exact, this syntax is not mentioned in the official documentation pages, but it does appear in the help section of view.m, which is viewable (no pun intended…) if you type the following in your Matlab console (R2014a or earlier, note the highlighted lines):
We all know the benefits of setting default class-property values: it saves coding, increases class readability, improves maintainability and reduces the potential for coding bugs due to uninitialized properties. Basically, we’re setting default values of the class properties, so that whenever a new instance of this class is created, it will be recreated with these same default property values. This is the behavior in any self-respecting OOP language, and is a well-entrenched paradigm in OOP computing. Simple enough, right?
Well, unfortunately it doesn’t behave quite this way in Matlab…
This blog post was supposed to be a piece of cake: The problem description was that we wish to display a text title next to the legend box in plot axes. Sounds simple enough. After all, in HG1 (R2014a and earlier), a legend was a simple wrapper around a standard Matlab axes. Therefore, we can simply access the legend axes’s title handle, and modify its properties. This works very well in HG1:
hold all; hLine1 = plot(1:5); hLine2 = plot(2:6); hLegend = legend([hLine1,hLine2], 'Location','NorthWest'); hTitle = get(hLegend,'title'); set(hTitle, 'String','Plot types:', 'VerticalAlignment','middle', 'FontSize',8);
How hard then could a corresponding solution be in HG2 (R2014b+), right?
Well, it turns out that hard enough (at least for me)…
Carlos David Peña liked this post