- Matlab toolstrip – part 1
- Customizing web-GUI uipanel
- Scrollable GUI panels
- Multi-threaded Mex
- Plot legend customization
- Sliders in Matlab GUI – part 2
- String/char compatibility
- Blocked wait with timeout for asynchronous events
- Speeding-up builtin Matlab functions – part 2
- Speeding-up builtin Matlab functions – part 1
- Spicing up the Matlab Editor
- Auto-scale image colors
- Adding custom properties to GUI objects
- IP address input control
- Desktop (44)
- Figure window (51)
- Guest bloggers (65)
- GUI (156)
- Handle graphics (82)
- Hidden property (41)
- Icons (15)
- Java (171)
- Listeners (22)
- Memory (16)
- Mex (13)
- Presumed future risk (380)
- Public presentation (6)
- Semi-documented feature (10)
- Semi-documented function (35)
- Stock Matlab function (137)
- Toolbox (9)
- UI controls (50)
- Uncategorized (13)
- Undocumented feature (205)
- 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 feature Semi-documented function Toolbar uicontrol uifigure UIInspect uitools Undocumented feature Undocumented function Undocumented property
- Yair Altman (3 days 2 hours ago): @Eddie – try to download the latest version of findjobj and then try again, it works well on all Matlab versions, including 18a and 18b.
- Paul Andrews (4 days 17 hours ago): Yair, This post is great. Thanks you for sharing this. I’ve been interested in building application with the toolstrip for quite a while, and I am really happy to see that it...
- Paul Andrews (4 days 17 hours ago): I am also having problems docking figures in a compiled application using the newer releases (R2016a and up). I’ve tried all of the suggestions above, but none of them...
- Eddie (6 days 21 hours ago): I just downloaded 2018b and findjobj does not work on uicontrol anymore For example, u=uicontrol; jobj=findjobj(u); Returns an empty handle in 2018b, but in 2018a that is not a...
- marc (18 days 23 hours ago): Thank you very much ! It did the job 😉
- KAE (20 days 0 hours ago): Thanks for your blog and book, very helpful. It’d be great if you could blog sometime about best practices for using Matlab’s neural network fitting (net, train), especially for getting...
- Collin Pecora (20 days 4 hours ago): Marc, I don’t understand why, but BusyAffordance uses the MJPanel‘s font to measure the busy text, but uses the UIManager’s Label.font to draw it. So, you...
- Yair Altman (20 days 5 hours ago): @Hironori – callback functions run asynchronously, not synchronously, so they do not return any value. You can save the results in some persistent place (like a global...
- Hironori Tokuno (20 days 6 hours ago): Hello Mr. Altman Thank you for this variable informations How could I get the Output variable from the function “myFunc2” using the command...
- Yair Altman (21 days 15 hours ago): I am not aware of a way to modify the text font. You might have thought that jObj.getComponent.setFont(jObj .getComponent.getFont.deriveFo nt(20)) would do the trick, but in...
- Marc (21 days 23 hours ago): Hi, How could we increase the size of the text below (“testing…”) ? Thanks
- Iliya (33 days 0 hours ago): Hi Khris, Thanks for sharing your attempt (and thoughts) regarding the key press listeners! I’m sure it would be a helpful starting point for those who would like to explore...
- Khris Griffis (33 days 18 hours ago): Great workaround Iliya! I was playing with something similar to this, though my approach was not as nice. I found that we can add listeners to the DOM for key presses and then...
- Blake (40 days 23 hours ago): This is a great article! Does anyone know the format of the header information in the converted bytestream? Thanks!
- Yair Altman (41 days 1 hour ago): In recent Matlab releases, Matlab’s pause is no less (sometimes even more) accurate than Java’s Thread.sleep, with a consistent mean inaccuracy (overhead) of 0.1-0.2...
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). You can read the full detailed technical article here.
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.
I have prepared the following online webinars on advanced Matlab topics I (click the webinar titles for a detailed description):
- Interactive Matlab GUI (3:26 hours) – $245 (buy)
- Advanced Matlab GUI (3:37 hours) – $245 (buy)
- Expert Matlab GUI (3:33 hours) – $245 (buy)
==> or buy all 3 Matlab GUI webinars for only $595 (buy)
- Matlab performance tuning part 1 (3:39 hours) – $245 (buy)
- Matlab performance tuning part 2 (3:43 hours) – $245 (buy)
==> or buy both Matlab performance tuning webinars for only $395 (buy)
- Object-oriented Matlab programming (3:36 hours) – $245 (buy)
- ==> or buy all 6 Matlab webinars (GUI, performance & OOP) for only $995 (buy)
All webinars are highly technical, concise and to the point, making very effective use of your time. They are based on onsite training courses that I presented at multiple client locations (details).
These webinars could be a great way for you to improve your Matlab proficiency and efficiency. You will quickly learn how to produce higher quality, better looking, faster working, and more robust applications. Your effectiveness in writing Matlab programs will improve, saving you development time while improving the quality. And all this at the comfort and convenience of your office or home.
Email me if you would like additional information or a group discount, or to inquire regarding an onsite training course, or for any other related query/suggestion.
Advanced Matlab training courses/seminars will be presented by me (Yair) in Zürich, Switzerland on 29-30 August, 2017:
- August 29 (full day) – Interactive Matlab GUI
- August 30 (full day) – Advanced Matlab GUI
The seminars are targeted at Matlab users who wish to improve their program’s usability and professional appearance. Basic familiarity with the Matlab environment and coding/programming is assumed. The courses will present a mix of both documented and undocumented aspects, which is not available anywhere else. The curriculum is listed below.
This is a unique opportunity to enhance your Matlab coding skills and improve your program’s usability in a couple of days.
If you are interested in either or both of these seminars, please Email me (altmany at gmail dot com).
I can also schedule a dedicated visit to your location, for onsite Matlab training customized to your organization’s specific needs. Additional information can be found on my Training page.
Around the time of the training, I will be traveling to various locations around Switzerland. If you wish to meet me in person to discuss how I could bring value to your project, then please email me (altmany at gmail):
- Geneva: Aug 22 – 27
- Bern: Aug 27 – 28
- Zürich: Aug 28 – 30
- Stuttgart: Aug 30 – 31
- Basel: Sep 1 – 3
A few months ago I wrote about various tricks for sending email/text messages from Matlab. Unfortunately, Matlab only sends text emails by default and provides no documented way to send HTML-formatted emails. Text-only emails are naturally very bland and all mail clients in the past 2 decades support HTML-formatted emails. Today I will show how we can send such HTML emails from Matlab.
A quick recap: Matlab’s sendmail function uses Java (specifically, the standard
javax.mail package) to prepare and send emails. The Java classes are extremely powerful and so there is no wonder that Mathworks chose to use them rather than reinventing the wheel. However, Matlab’s sendmail function only uses part of the functionality exposed by these classes (admittedly, the most important parts that deal with the basic mail-sending mechanism), and does not expose external hooks or input args that would enable the user to take full advantage of the more advanced features, HTML formatting included.
Only two small changes are needed in sendmail.m to support HTML formatting:
- HTML formatting required calling the message-object’s setContent() method, rather than setText().
- We need to specify
'text/html'as part of the message’s encoding