- Improving graphics interactivity
- Interesting Matlab puzzle – analysis
- Interesting Matlab puzzle
- Undocumented plot marker types
- Matlab toolstrip – part 9 (popup figures)
- Matlab toolstrip – part 8 (galleries)
- Matlab toolstrip – part 7 (selection controls)
- Matlab toolstrip – part 6 (complex controls)
- Matlab toolstrip – part 5 (icons)
- Matlab toolstrip – part 4 (control customization)
- Reverting axes controls in figure toolbar
- Matlab toolstrip – part 3 (basic customization)
- Matlab toolstrip – part 2 (ToolGroup App)
- Matlab toolstrip – part 1
- Desktop (45)
- Figure window (59)
- Guest bloggers (65)
- GUI (165)
- Handle graphics (84)
- Hidden property (42)
- Icons (15)
- Java (174)
- Listeners (22)
- Memory (16)
- Mex (13)
- Presumed future risk (393)
- Public presentation (6)
- Semi-documented feature (10)
- Semi-documented function (35)
- Stock Matlab function (139)
- Toolbox (9)
- UI controls (52)
- Uncategorized (13)
- Undocumented feature (217)
- Undocumented function (37)
TagsAppDesigner 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 Toolstrip uicontrol uifigure UIInspect uitools Undocumented feature Undocumented function Undocumented property
- Doug (10 hours 54 minutes ago): I’d love to be able to customize the appearance of the axes toolbar rather than replacing it. Frustratingly my attempts have led to not very much success, I can move it from...
- Yair Altman (3 days 13 hours ago): @Mike – you can modify the tip background via the TipHandle and/or BackgroundAlpha: hDataTip.TipHandle.FaceColor = 'm'; % or: [1,0,1] hDataTip.BackgroundAlpha = 0.65;
- Yair Altman (3 days 13 hours ago): @Jafa – the simplest way to add buttons is to adapt the Matlab source-code of the uigetfile_with_preview utility (around line #95) by adding Matlab uicontrols in the...
- Yair Altman (3 days 15 hours ago): @Andreas – as far as I could see there is no change in R2019a.
- Andreas (3 days 15 hours ago): Great article. Do you know if something changed with R2019a? Is MathWorks working on this new “feature” and improving it?
- Matlabler (7 days 11 hours ago): Great tip, thank you! I speeded up the rangesearch function this way. I just replaced it with pdist2(X,Y,distance,’RAD IUS’,radius); and now I save 93% of the time it...
- Dima (15 days 14 hours ago): Hey Yair, As you said, in the new MATLAB versions the pause performs the same or even better for some pause duration. The interesting thing is that for time duration in between >1ms...
- Wolfgang (16 days 2 hours ago): ok, shame on me Yair, obviously it wasn’t the plot handle, might have been too late. I had another look and of course you’re right, it works. Peter Rochford’s...
- Mike Papadopoulos (16 days 5 hours ago): Using MATLAB 2018b, I have been able to change the EdgeColor and TextColor of the datatip, but the BackgroundColor will not update properly. Specifically the...
- Jafa (20 days 4 hours ago): Hello Yair, thanks a lot for your helpful work! Regarding uigetfile customizations, I am curious if there is the possibility of having multiple buttons (in my case I am looking for a...
- Gebhard Stopper (24 days 16 hours ago): Hi, I really love this mini series! (I’ve been looking for something like this for quite a while) I have two questions about the toolstrip: 1) (How) Is it possible to...
- Simon (25 days 8 hours ago): Does anyone know if multi line tooltips are possible for Digraph plots? This strategy doesn’t appear to work…
- Thomas Satterly (30 days 5 hours ago): Thanks for writing this series, I’ve found using the ToolGroup very enjoyable in new lightweight apps. One issue/annoyance I’ve noticed is that conditional tab...
- Hossein (32 days 22 hours ago): Hi, I changed the size of matrices from 4 to 10000, i.e. matrix1=rand(10000) and matrix2=rand(10000); Then, I compared the speed in terms of the number of the threads. For...
- Arash Marashian (37 days 6 hours ago): Hi, Dear Yair, Thank you for your information. I have a question in “showcaseMPCDesigner.m 8221;, we have a function named “createDialog”, that makes a...
I planned to post a new article in my toolstrip mini-series, but then I came across something that I believe has a much greater importance and impacts many more Matlab users: the change in Matlab R2018b’s figure toolbar, where the axes controls (zoom, pan, rotate etc.) were moved to be next to the axes, which remain hidden until you move your mouse over the axes. Many users have complained about this unexpected change in the user interface of such important data exploration functionality:
Luckily, we can revert the change, Continue reading
In the previous post I showed how we can create custom Matlab apps. In such apps, the toolstrip is very often an important part. Today I continue my miniseries on toolstrips. Toolstrips can be a bit complex so I’m trying to proceed slowly, with each post in the miniseries building on the previous posts. So I encourage you to review the earlier posts in the miniseries (part1, part2) before reading this post.
A Matlab toolstrip is composed of a hierarchy of user-interface objects as follows (all objects are classes within the
In this post I explain how we can create a custom toolstrip that contains tabs, sections, and basic controls that interact with the user and the docked figures. The following posts will show more advanced customizations and more complex controls, as well as showing alternative ways of creating the toolstrip.
A while ago I posted the first of my planned miniseries on the Matlab toolstrip (ribbon). Today I will expand that post by discussing how toolstrips can be added to Matlab GUIs. This post will remain at a high-level as the previous post, with followup posts drilling into the technical details of the toolstrip components (inner packages and classes).
We can add a Matlab toolstrip to 3 types of Matlab GUI windows:
- To a Java-based Matlab figure (so-called “legacy” figures, created using GUIDE or the figure function)
- To a container window of docked Java-based figures, typically called an “App” (marketing name) or “Tool Group” (internal technical name)
Today I will show how to add a basic dynamic toolstrip to a ToolGroup (App, window type #2):
The Matlab toolstrip (ribbon) has been around officially since R2012a, and unofficially for a couple of years earlier. Since then, I blogged about the toolstrip only rarely (example). I believe the time has come to start a short mini-series about this functionality, eventually showing how users can use toolstrips in their own custom applications.
My plan is to start the miniseries with a discussion of the built-in showcase examples, followed by a post on the built-in classes that make up the toolstrip building-blocks. Finally, I’ll describe how toolstrips can be added to figures, not just in client/tool groups.
Matlab’s internal showcase examples
I start the discussion with a description of built-in examples for the toolstrip functionality, located in %matlabroot%/toolbox/matlab/toolstrip/+matlab/+ui/+internal/+desktop/. The most important of these are showcaseToolGroup.m and showcaseMPCDesigner.m, both of which use Java-based (Swing) containers and controls. Readers who wish to integrate toolstrips into their app immediately, without waiting for my followup posts in this series, are welcome to dig into the examples’ source-code and replicate it in their programs:
h = matlab.ui.internal.desktop.showcaseToolGroup
Today I’d like to share a technique I’ve been experimenting with, allowing Matlab to respond to pretty much any JS event to which we can attach a listener. This is an overview of how it works:
- create a UIFigure with the desired contents, and add to it (at least) one more dummy control, which has an associated Matlab callback.
- execute a JS snippet that programmatically interacts with the dummy control, whenever some event-of-interest happens, causing the Matlab callback to fire.
- query the
webWindow, from within the Matlab callback, to retrieve any additional information (“payload”) that the JS passed.
This approach allows, for example, to easily respond to mouse events:
I would like to introduce guest blogger Khris Griffis. Today, Khris will continue the series of posts on web-based uifigure customization with an article showing how to create scrollable/customizable panels in web-based uifigures. This post follows last-week’s article, about placing controls/axes within a scroll-panel in non-web (Java-based) figures. Users interested in advanced aspects and insights on the development roadmap of web-based Matlab GUI should also read Loren Shure’s blog post from last week.
As a retinal physiologist, I spend a lot of time in Matlab creating GUIs to visualize and analyze electrophysiological data. The data often requires a lot of processing and quality control checks before it can be used for interpretation and publication. Consequently, I end up with many control elements taking up precious space on my GUI.
In Java-based (legacy/GUIDE) figures, this wasn’t a huge problem because, depending on what GUI components I needed, I could use a pure Matlab approach (a child panel within a parent panel, with a couple of control sliders moving the child panel around), or a number of Java approaches (which are always more fun; Yair described such an approach last week).
Unfortunately, the web-based (App-Designer) figure framework doesn’t support Java, and the pure/documented Matlab approach just doesn’t look good or function very well:
AppDesigner uislider is not a good scrollbar, no matter what we do to it!
<div> with a Matlab-designed CSS style. We can customize it with little effort.
The main goal here is to create a scrollable customizable uipanel containing many uicontrol elements, which could look something like this:
Matlab enables two types of GUI container types, via the Units property: fixed-size (
'chars', etc.) and flexible (
'normalized'). In many cases, we need something in between: a panel that expands dynamically when its container grows (i.e., flexible/
Scrollable Matlab GUI panel
I was recently asked by a consulting client to help speed up a Matlab process. Quite often there are various ways to improve the run-time, and in this particular case it turned out that the best option was to convert the core Matlab processing loop into a multi-threaded Mex function, while keeping the rest (vast majority of program code) in easy-to-maintain Matlab. This resulted in a 160x speedup (25 secs => 0.16 secs). Some of this speedup is attributed to C-code being faster in general than Matlab, another part is due to the multi-threading, and another due to in-place data manipulations that avoid costly memory access and re-allocations.
In today’s post I will share some of the insights relating to this MEX conversion, which could be adapted for many other similar use-cases. Additional Matlab speed-up techniques can be found in other performance-related posts on this website, as well in my book Accelerating MATLAB Performance.
There are quite a few online resources about creating Mex files, so I will not focus on this aspect. I’ll assume that the reader is already familiar with the concept of using Mex functions, which are simply dynamically-linked libraries that have a predefined entry-function syntax and predefined platform-specific extension. Instead, I’ll focus on how to create and debug a multi-threaded Mex function, so that it runs in parallel on all CPU cores.
The benefit of multi-threading is that threads are very light-weight objects, that have minimal performance and memory overheads. This contrasts to multi-tasking, which is what the Parallel Computing Toolbox currently does: launches duplicate copies of the entire Matlab engine process (“headless workers”) and then manages and coordinates the tasks to split up the processing work. Multi-tasking should be avoided wherever we can employ light-weight multi-threading instead. Unfortunately, Matlab does not currently have the ability to explicitly multi-thread Matlab code. But we can still use explicit multi-threading by invoking code in other languages, as I’ve already shown for Java, C# (and .NET in general), and C/C++. Today’s article will expand on the latter post (the one about C/C++ multi-threading), by showing a general framework for making a multi-threaded C-based Mex function.
Three years ago I explained how we can use a couple of undocumented hidden properties of the legend in order to add a legend title (the legend object had no Title property back then – this was only added in a later Matlab release, perhaps as a result of my post). Today I will expand on that article by explaining the plot legend’s internal graphics hierarchy, how we can access each of these components, and then how this information could be used to customize the separate legend components. Note that the discussion today is only relevant for HG2 legends (i.e. R2014b or newer).
Let’s start with a simple Matlab plot with a legend:
hold all; hLine1 = plot(1:5); hLine2 = plot(2:6); hLegend = legend([hLine1,hLine2], 'Location','SouthEast'); hLegend.Title.String = 'MyLegend';
Exactly 3 years ago I posted about various alternatives for embedding sliders in Matlab GUI. Today I will follow up on that post with a description of yet another undocumented builtin alternative – controllib.widget.Slider. A summary of the various alternatives can be seen in the following screenshot:
The controllib.widget.Slider component is a class in Matlab’s internal
controllib package (last week I discussed a different utility function in this package, controllib.internal.util.hString2Char).