- Toolbar button labels
- Using SQLite in Matlab
- PlotEdit context-menu customization
- Builtin PopupPanel widget
- Customizing uifigures part 3
- Customizing contour plots part 2
- The HotLinks feature
- Tips for accelerating Matlab performance
- Faster csvwrite/dlmwrite
- Runtime code instrumentation
- Advanced Matlab online webinars
- Matlab GUI training seminars – Zurich, 29-30 August 2017
- Sending HTML emails from Matlab
- User-defined tab completions – take 2
- Matlab Expo – Bern, 22 June 2017
- Desktop (42)
- Figure window (50)
- Guest bloggers (59)
- GUI (149)
- Handle graphics (77)
- Hidden property (41)
- Icons (7)
- Java (166)
- Listeners (20)
- Memory (15)
- Mex (12)
- Presumed future risk (363)
- Public presentation (6)
- Semi-documented feature (9)
- Semi-documented function (33)
- Stock Matlab function (133)
- Toolbox (7)
- UI controls (49)
- Uncategorized (13)
- Undocumented feature (195)
- Undocumented function (37)
TagsActiveX AppDesigner Callbacks COM Compiler Desktop Donn Shull Editor Figure FindJObj GUI GUIDE Handle graphics HG2 Hidden property HTML Icons Internal component Java JavaFrame JIDE JMI Listener Malcolm Lidierth MCOS Memory Menubar Mex Optical illusion Performance Profiler Pure Matlab schema schema.class schema.prop Semi-documented function Toolbar uicontrol uifigure UIInspect uitable uitools Undocumented feature Undocumented function Undocumented property
- Yair Altman (4 days 1 hour ago): Set the node’s label to an HTML fixed-width font, for example: '<html><pre>tree node label</pre>'
- Geert van Kempen (4 days 20 hours ago): Would anybody know how I can use a Fixed Width font in a uitreenode?
- Tiago Dias (6 days 1 hour ago): Hello, I was wondering if is possible just to change the width of the Square of the plot. Using the BoxFrame i manage to change the width of the square and the grid, but I only...
- Sarunas (6 days 2 hours ago): Update: Since “the one” used instance of EXCEL is closed inside other called functions (like xlsread/xlswrite), I had to hide some of the code there to prevent the...
- Yair Altman (6 days 5 hours ago): @JoeB – the Mathworks’ CheckBoxList has a bug with this: the list is indeed disabled in the sense that you cannot change the selected item(s), but it is not fully...
- Yair Altman (6 days 20 hours ago): I just added an addendum to the main post that explains how to set the uipanel’s background to transparent in HG2 (R2014b onward)
- Sarunas (14 days 7 hours ago): Or maybe I was too joyful too quickly. Apparently if there is an excel window open, I get an error and/or the window is closed.
- Sarunas (14 days 9 hours ago): I had a program that reads two excel files (== two tables) and returns an excel with 10 sheets, 2 – 3 tables each sheet. I used WRITETABLE, I had to use that for every table,...
- Jeffery Devereux (21 days 2 hours ago): Hl Shi, by installing the 1 sec pause, I was able to get the controller array loaded. Otherwise it is empty. Still poking around with it however it did work. just set MyICO...
- Wilber (21 days 19 hours ago): Yair Am I doing something wrong? I can’t correct the problem. Can you help me please. This is the code: f = GXFigure(); set(f.Parent, 'Units', 'normalized', 'Position', [.2 .2...
- JoeB (29 days 1 hour ago): Hi Yair, Thanks for this. When I try the following code in ML 2017a, I get a list that returns IsEnabled as false but still allows the user to change the checkbox values and does not...
- Marie Jeanneteau (30 days 17 hours ago): @Zach Mauch Have you found a way to solve your problem ? I am in the same case and was only using jRangeSlider because it is an easy way to use a ‘good looking’...
- Peter Cook (32 days 19 hours ago): @Alon This method runs very slow for a complex contour (e.g. not necessarily in size but perhaps one generated from real, noisy, data), which led me to experiment with some other...
- Alon (35 days 2 hours ago): Hello Yair, Note that if there are unused contour lines, as may be the case when hContour.LevelListMode is set to manual, the above code will not work, as hContour.EdgePrims enumerates...
- Yair Altman (35 days 9 hours ago): @sipsj11 – you are very mistaken: first, the method of setting the figure’s position to [0 0 1 1] has existed forever, not just since HG2. Secondly, this method is...
I was recently asked by a client to add a few buttons labeled “1”-“4” to a GUI toolbar. I thought: How hard could that be? Simply get the toolbar’s handle from the figure, then use the builtin uipushtool function to add a new button, specifying the label in the String property, right?
Well, not so fast it seems:
hToolbar = findall(hFig, 'tag','FigureToolBar'); % get the figure's toolbar handle uipushtool(hToolbar, 'String','1'); % add a pushbutton to the toolbar Error using uipushtool There is no String property on the PushTool class.
Apparently, for some unknown reason, standard Matlab only enables us to set the icon (CData) of a toolbar control, but not a text label.
Once again, Java to the rescue: Continue reading
MathWorks invests a huge amount of effort in recent years on supporting large distributed databases. The business case for this focus is entirely understandable, but many Matlab users have much simpler needs, which are often served by the light-weight open-source SQLite database (which claims to be the most widely-used database worldwide). Although SQLite is very widely used, and despite the fact that built-in support for SQLite is included in Matlab (for its internal use), MathWorks has chosen not to expose any functionality or wrapper function that would enable end-users to access it. In any case, I recently came across a need to do just that, when a consulting client asked me to create an interactive data-browser for their SQLite database that would integrate with their Matlab program:
In today’s post I will discuss several possible mechanisms to integrate SQLite in Matlab code, and you can take your pick among them. Except for the Database Toolbox, all the alternatives are free (open-source) libraries (even the commercial Database Toolbox relies on one of the open-source libraries, by the way).
Prasad Kalane liked this post
Last week, a Matlab user asked whether it is possible to customize the context (right-click) menu that is presented in plot-edit mode. This menu is displayed by clicking the plot-edit (arrow) icon on the standard Matlab figure toolbar, then right-clicking any graphic/GUI element in the figure. Unfortunately, it seems that this context menu is only created the first time that a user right-clicks in plot-edit mode – it is not accessible before then, and so it seems impossible to customize the menu before it is presented to the user the first time.
A few workarounds were suggested to the original poster and you are most welcome to review them. There is also some discussion about the technical reasons that none of the “standard” ways of finding and modifying menu items fail in this case.
In today’s post I wish to repost my solution, in the hope that it might help other users in similar cases.
My solution is basically this:
8 years ago I blogged about Matlab’s builtin HelpPopup widget. This control is used by Matlab to display popup-windows with help documentation, but can also be used by users to display custom lightweight popups that contain HTML-capable text and even URLs of entire webpages. Today I’d like to highlight another builtin Matlab widget,
ctrluis.PopupPanel, which can be used to display rich contents in a lightweight popup box attached to a specific Matlab figure:
As you can see, this popup-panel displays richly-formatted contents, having either an opaque or transparent background, with vertical scrollbars being applied automatically. The popup pane is not limited to displaying text messages – in fact, it can display any Java GUI container (e.g. a settings panel). This popup-panel is similar in concept to the HelpPopup widget, and yet much more powerful in several aspects.
Customization hacks reported on this blog last year (part 1, part 2) may fail in some cases due to the changing nature of the undocumented internals. Some examples are the way by which we can extract the uifigure’s URL (which changed in R2017a), the ability to display and debug uifigures in a standard webbrowser with associated dev tools (which seems to have stopped working in R2017b), and the way by which we can extract the Dijit reference of displayed uicontrols.
Greatly assisting in this respect is Iliya Romm, who was the guest blogger for part 2 of this series last year. Iliya co-authored the open-source (GitHub) mlapptools toolbox, which enables accessing and customizing uifigure components using standard CSS, without users having to bother about the ugly hacks discussed in the previous parts of the series. This toolbox is really just a single Matlab class (
mlapptools), contained within a single m-file (mlapptools.m). In addition to this class, the toolbox includes a README.md mark-down usage documentation, and two demo functions, DOMdemoGUI.m and TableDemo.m.
Here is the effect of using TableDemo, that shows how we can customize individual uitable cells (each uitable cell is a separate Dijit widget that can be customized individually):
A few weeks ago a user posted a question on Matlab’s Answers forum, asking whether it is possible to display contour labels in the same color as their corresponding contour lines. In today’s post I’ll provide some insight that may assist users with similar customizations in other plot types.
Matlab does not provide, for reasons that escape my limited understanding, documented access to the contour plot’s component primitives, namely its contour lines, labels and patch faces. Luckily however, these handles are accessible (in HG2, i.e. R2014b onward) via undocumented hidden properties aptly named EdgePrims, TextPrims and FacePrims, as I explained in a previous post about contour plots customization, two years ago.
Let’s start with a simple contour plot of the peaks function:
[X,Y,Z] = peaks; [C,hContour] = contour(X,Y,Z, 'ShowText','on', 'LevelStep',1);
The result is the screenshot on the left:
In order to update the label colors (to get the screenshot on the right), we create a short
updateContours function that updates the TextPrims color to their corresponding EdgePrims color:
Back in 2010, I posted about Matlab’s undocumented feature function. One of the features that I mentioned was
'HotLinks'. A few days ago I had an occasion to remember this feature when a StackOverflow user complained that the headers of table outputs in the Matlab console appear with HTML tags (<strong>) in his diary output. He asked whether it was possible to turn off this automated headers markup.
There are several ways this problem can be solved, ranging from creating a custom table display function, to modifying the table’s internal disp method (%matlabroot%/toolbox/matlab/datatypes/@tabular/disp.m), to using this method’s second optional argument (
disp(myTable,false)). Note that simply subclassing the
table class to overload disp() will not work because the
table class is Sealed, but we could instead subclass
table‘s superclass (
tabular) just like
Inside the disp.m method mentioned above, the headers markup is controlled (around line 45, depending on your Matlab release) by
matlab.internal.display.isHot. Unfortunately, there is no corresponding setHot() method, nor corresponding m- or p-code that can be inspected. But the term “Hot” rang a bell, and then I remembered my old post about the HotLinks feature, which is apparently reflected by
feature('HotLinks',false); % temporarily disable bold headers and hyperlinks (matlab.internal.display.isHot=false) disp(myTable) myTable % this calls disp() implicitly feature('HotLinks',true); % restore the standard behavior (markup displayed, matlab.internal.display.isHot=true)
Searching for “isHot” or “HotLinks” under the Matlab installation folder, we find that this feature is used in hundreds of places (the exact number depends on your installed toolboxes). The general use appears to be to disable/enable output of hyperlinks to the Matlab console, such as when you display a Matlab class, when its class name is hyperlinked and so is the “Show all properties” message at the bottom. But in certain cases, such as for the
table output above, the feature is also used to determine other types of markup (bold headers in this case).
I’m proud to report that MathWorks has recently posted my article “Tips for Accelerating MATLAB Performance” in their latest newsletter digest (September 2017). This article is an updated and expanded version of my post about consulting work that I did for the Crustal Dynamics Research Group at Harvard University, where I helped speed-up a complex Matlab-based GUI by a factor of 50-500 (depending on the specific feature).
Matlab’s builtin functions for exporting (saving) data to output files are quite sub-optimal (as in slowwwwww…). I wrote a few posts about this in the past (how to improve fwrite performance, and save performance). Today I extend the series by showing how we can improve the performance of delimited text output, for example comma-separated (CSV) or tab-separated (TSV/TXT) files.
The basic problem is that Matlab’s dlmwrite function, which can either be used directly, or via the csvwrite function which calls it internally, is extremely inefficient: It processes each input data value separately, in a non-vectorized loop. In the general (completely non-vectorized) case, each data value is separately converted into a string, and is separately sent to disk (using fprintf). In the specific case of real data values with simple delimiters and formatting, row values are vectorized, but in any case the rows are processed in a non-vectorized loop: A newline character is separately exported at the end of each row, using a separate fprintf call, and this has the effect of flushing the I/O to disk each and every row separately, which is of course disastrous for performance. The output file is indeed originally opened in buffered mode (as I explained in my fprintf performance post), but this only helps for outputs done within the row – the newline output at the end of each row forces an I/O flush regardless of how the file was opened. In general, when you read the short source-code of dlmwrite.m you’ll get the distinct feeling that it was written for correctness and maintainability, and some focus on performance (e.g., the vectorization edge-case). But much more could be done for performance it would seem.
This is where Alex Nazarovsky comes to the rescue.
I regularly follow the MathWorks Pick-of-the-Week (POTW) blog. In a recent post, Jiro Doke highlighted Per Isakson’s tracer4m utility. Per is an accomplished Matlab programmer, who has a solid reputation in the Matlab user community for many years. His utility uses temporary conditional breakpoints to enable users to trace calls to their Matlab functions and class methods. This uses a little-known trick that I wish to highlight in this post.
Matlab breakpoints are documented and supported functionality, and yet their documented use is typically focused at interactive programming in the Matlab editor, or as interactive commands that are entered in the Matlab console using the set of db* functions: dbstop, dbclear, dbstatus, dbstack etc. However, nothing prevents us from using these db* functions directly within our code.