- Enclose with " for exact match e.g., "uitable report"
- Advanced on-site Matlab training, amazing value - additional info
- JGraph in Matlab figures
- 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
- Desktop (35)
- Figure window (36)
- Guest bloggers (48)
- GUI (123)
- Handle graphics (66)
- Hidden property (34)
- Icons (7)
- Java (141)
- Listeners (18)
- Memory (14)
- Mex (9)
- Presumed future risk (296)
- 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
- Iliya (1 hour 33 minutes ago): I remembered that this issue was discussed in your blog before. I must’ve hidden the warning in the past…
- Iliya (1 hour 38 minutes ago): Hello Yair, I started seeing the following warning when trying to access the JavaFrame property: Warning: figure JavaFrame property will be obsoleted in a future release. For more...
- Yair Altman (5 hours 7 minutes ago): @Karai – you can get the *.java source code from here: http://undocumentedmatlab.com/ files/examplewindow.zip Unfortunately I do not have access to the original...
- Yair Altman (5 hours 16 minutes ago): @Brian – jh.setBorderPainted(false); % or: jh.BorderPainted=false;
- Yair Altman (5 hours 20 minutes ago): @SCMG – yes, com.mathworks.mlwidgets.dialog .ProgressBarDialog was removed in R2014b. As to why you don’t see the spinning circle, try to add a call to drawnow and...
- Yair Altman (12 hours 0 minutes ago): @Yumin – you can create the Java GUI and then call the GUI’s main class directly from Matlab. See the relevant Matlab docs. You can also use transparency directly in...
- Yumin Sun (14 hours 22 minutes ago): Hi Yair, I want to write a GUI in Java first and then call it from Matlab,is that possible? Because I need to load some pictures with transparent background and then let them...
- scmg (2 days 21 hours ago): Hi, i’m trying your example for BusyAffordance in a listbox. When the listbox’s CallbackFcn is called, i want to set listbox’s ‘Enable’ to...
- Yair Altman (5 days 11 hours ago): @Sam – thanks for confirming that BDE does indeed stand for Block Diagram Editor as I’ve speculated. As I noted in the main text, MathWorks removed BDE from the core...
- Yair Altman (5 days 11 hours ago): @Sam – thanks for the detailed feedback
- Sam Roberts (5 days 11 hours ago): Yair – just in case you’re still interested (I appreciate that this is a very old post I’m replying to), BDE is short for block diagram editor. It’s part...
- Sam Roberts (5 days 11 hours ago): Hi Scott and Yair, I’ve used JGraphX quite a bit within MATLAB UIs, and have a couple of suggestions based on my experience. i) When you create the mxGraphComponent,...
- Yaroslav (6 days 3 hours ago): Hi Yair, Regarding the new HG2 system: it seems that TMW have sealed all the graphic classes and widgets from sub-classing. They have also concealed (by pcode) the implementation,...
- Bryan Moosman (6 days 9 hours ago): Hello Yair, I’ve tried both the code above and the functions you submitted. I’ve got 2 areas of feedback: 1. The figure sizing isn’t quite correct. It was a...
- Brian (6 days 14 hours ago): Hello Yair, Thanks for all your work on this site. I’ve had a heck of a time trying to figure out how to do a border-less button. I tried using both the null vector...
I would like to introduce guest blogger Scott Koch. Scott is part of the development team at Eigenvector Research Inc., makers of PLS_Toolbox, a commercial chemometrics and multivariate data analysis toolbox. Today Scott will expand on JGraph, a Java-based open source graph visualization and diagramming library.
What is JGraph?
Graphing is a powerful visualization tool that has not yet been integrated into the core Matlab product. I assume that this will be rectified by MathWorks in a future Matlab release. But until that time, or even later if you are still using R2015a or older, we do not have a solution in the core Matlab. In our toolbox product, we use a cleverly designed image to display a simple diagram, but I always thought it would be nice to have a “real” diagramming tool that was interactive and full-featured.
So, as a long time follower of Yair’s blog, I was thrilled to see his post several years ago about integrating Java libraries for charting and diagramming in Matlab figures. Unfortunately, my first attempts at getting JGraph to work in Matlab were not very successful. Thanks to a comment on that original post by Markus Behle, I was able to gain full access to JGraph in Matlab. Today’s post will show how we can use JGraph in Matlab.
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…