- Enclose with " for exact match e.g., "uitable report"
- Advanced
**on-site Matlab training**- amazing value ### Useful links

### Recent Posts

- Convolution performance
- I am hiring a Matlab programmer (Tel Aviv)
- Graphic sizing in Matlab R2015b
- Programmatic shortcuts manipulation – part 2
- Programmatic shortcuts manipulation – part 1
- Solving a Matlab MCOS bug
- Customizing contour plots
- Figure keypress modifiers
- Enabling user callbacks during zoom/pan
- Hyperlink text labels
- Font selection components
- Adding dynamic properties to graphic handles
- Callback functions performance
- Solving an mput (FTP) hang problem
- Accessing internal Java class members

### Archives

### Categories

- Desktop (37)
- Figure window (40)
- Guest bloggers (50)
- GUI (130)
- Handle graphics (71)
- Hidden property (36)
- Icons (7)
- Java (147)
- Listeners (20)
- Memory (14)
- Mex (9)
- Presumed future risk (314)
- Semi-documented feature (7)
- Semi-documented function (31)
- Stock Matlab function (121)
- Toolbox (4)
- UI controls (42)
- Uncategorized (11)
- Undocumented feature (162)
- Undocumented function (32)

### Tags

ActiveX 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 scribe Semi-documented function Toolbar uicontrol UIInspect uitable uitools uiundo Undocumented feature Undocumented function Undocumented property### Recent Comments

- Yair Altman (2 days 13 hours ago): @Ale – First, did you really expect some undocumented functionality that I wrote about back in 2009 to continue working in 2015 ?! Be realistic! Secondly, it turns out...
- Krishnan (2 days 21 hours ago): Yair, I think I have a method of adding and removing from static class path, but I am unable to make it stick on subsequent restarts of Matlab. The idea is to use...
- Yair Altman (3 days 1 hour ago): @Chuck – don’t delete the component, but rather its Matlab container. This will work in both R2013b and R2015b: [jc,hc] = javacomponent(label,...); ... delete(hc)
- Yair Altman (4 days 0 hours ago): no Alex
- Alex Poulsen (4 days 5 hours ago): Would italicized text be possible?
- Yair Altman (5 days 23 hours ago): The code that is launched by the button callback runs on a separate thread so waitfor simply blocks execution of that thread, and other callbacks can still process. This is...
- Johan (6 days 8 hours ago): Hi Yair, I stumbled onto this page when trying to solve my conundrum. I’m trying to get ‘waitfor/uiwait’ to hold for a message box in a callback. I made a minimum...
- Yair Altman (7 days 18 hours ago): Yes of course. But since you neglected to come back here and update that you have found a solution, causing me and other readers extra effort to look for a solution, I thought...
- Carl Witthoft (8 days 19 hours ago): Yep, at least for me drawnow solved the problem. I was the OP for that SO question, btw
- Yair Altman (8 days 22 hours ago): Cross-referenced solution (as for Fabian’s issue above, to add a call to drawnow): http://stackoverflow.com/a/350 70679/233829
- Carl Witthoft (9 days 15 hours ago): (sorry about directly emailing – I missed your warnings) Hi – re your column on assigning transparency to plot markers: I tried the code on a simple example and...
- Ale (9 days 16 hours ago): What about setting a keyboard shortcut for a custom shortcut? I have some shortcut that I use really often, but I have to click on them all the time… Ale
- Dan Dolan (11 days 5 hours ago): I’m also puzzled by this message. I can tweak resolution settings, but not precisely enough to actually calibrate this screen.
- Efraïm Salari (12 days 0 hours ago): Works perfect! Thanks for the help.
- Dan (12 days 5 hours ago): Looks like the property is still not modifiable in 2016a. The error message informs us to simply change the resolution in our OS. Right. >> set(0, 'ScreenPixelsPerInch',100); Warning:...

### Contact Us

## Convolution performance

MathWorks’ latest MATLAB Digest (January 2016) featured my book “Accelerating MATLAB Performance“. I am deeply honored and appreciative of MathWorks for this.

I would like to dedicate today’s post to a not-well-known performance trick from my book, that could significantly improve the speed when computing the convolution of two data arrays. Matlab’s internal implementation of convolution (* conv*,

*and*

**conv2***) appears to rely on a sliding window approach, using implicit (internal) multithreading for speed.*

**convn**However, this can often be sped up significantly if we use the Convolution Theorem, which states in essence that * conv(a,b) = ifft(fft(a,N) .* fft(b,N))*, an idea proposed by Bruno Luong. In the following usage example we need to remember to zero-pad the data to get comparable results:

% Prepare the input vectors (1M elements each) x = rand(1e6,1); y = rand(1e6,1); % Compute the convolution using the builtin conv() tic, z1 = conv(x,y); toc => Elapsed time is 360.521187 seconds. % Now compute the convolution using fft/ifft: 780x faster! n = length(x) + length(y) - 1; % we need to zero-pad tic, z2 = ifft(fft(x,n) .* fft(y,n)); toc => Elapsed time is 0.463169 seconds. % Compare the relative accuracy (the results are nearly identical) disp(max(abs(z1-z2)./abs(z1))) => 2.75200348450538e-10

This latest result shows that the results are nearly identical, up to a a very minute difference, which is certainly acceptable in most cases when considering the enormous performance speedup (780x in this specific case). Bruno’s implementation (* convnfft*) is made even more efficient by using MEX in-place data multiplications, power-of-2 FFTs, and use of GPU/Jacket where available.

It should be noted that the builtin Matlab functions can still be faster for relatively small data arrays, or if your machine has a large number of CPU cores and free memory that Matlab’s builtin * conv** functions can utilize, and of course also depending on the Matlab release. So, your mileage might well vary. But given the significant speedup potential, I contend that you should give it a try and see how well it performs on your specific system and data.

If you have read my book, please be kind enough to post your feedback about it on Amazon (link), for the benefit of others. Thanks in advance!

Yahel Ben-David liked this post

## I am hiring a Matlab programmer (Tel Aviv)

I am hiring a Matlab programmer for work in the Tel Aviv area, under my supervision. Flexible workhours, suitable for part-time job seekers and students. The work will be interesting and the compensation good. I am not looking for a Matlab expert, but after some time working with me you will become one. If you live in the area and are interested, or if you know someone who could be a good fit, please email me: altmany at gmail.

אני מגייס מתכנת/ת מטלב לעבודה באזור פתח תקוה / בקעת אונו. המשרה בהיקף ובימים/שעות גמישים, מתאים לסטודנטים ולמשרה חלקית. העבודה מעניינת והשכר טוב. אני לא מחפש מומחי מטלב, אבל כעבור זמן מסויים של עבודה איתי אתם תהפכו לכאלו. לפרטים נא לפנות בדוא”ל ל

altmany at gmail

## Graphic sizing in Matlab R2015b

*I would like to introduce Daniel Dolan of Sandia National Laboratories. Dan works on a variety of data analysis projects in Matlab, and is an active lurker on MATLAB Central. Dan has a habit of finding interesting bugs for the Mac version of Matlab. Today he will discuss graphic sizing in Matlab and important changes that occurred in release R2015b.*

Matlab-generated graphics are often not displayed at their requested size. This problem has been known for some time and has a well-known solution: setting the root object’s **ScreenPixelsPerInch** property to the display’s actual DPI (dots per inch) value. Release R2015b no longer supports this solution, creating problems for publication graphics and general readability.

Continue reading

## Programmatic shortcuts manipulation – part 2

Today I will expand last week’s post on customizing Matlab Desktop’s shortcuts. I will show that we can incorporate non-standard controls, and add tooltips and user callbacks in undocumented ways that are not available using the interactive Desktop GUI.

Continue reading

## Programmatic shortcuts manipulation – part 1

User-defined shortcuts can interactively be added to the Matlab Desktop to enable easy access to often-used scripts (e.g., clearing the console, running a certain program, initializing data etc.). Similarly, we can place shortcuts in the help browser to quickly access often-used pages. Unfortunately, both of these shortcut functionalities, like many other functionalities of the Matlab Desktop and related tools (Editor, Browser, Profiler etc.), have no documented programmatic access.

Such programmatic access is often useful. For example, a large company for which I consult is using centralized updates to users’ shortcuts, in order to manage and expose new features for all Matlab users from a central location. It is easy to send updates and manage a few users, but when your organization has dozens of Matlab users, centralized management becomes a necessity. It’s a pity that companies need to resort to external consultants and undocumented hacks to achieve this, but I’m not complaining since it keeps me occupied…

Today’s post will describe “regular” shortcuts – those that are simple clickable buttons. Next week I will show how we can extend this to incorporate other types of shortcut controls, as well as some advanced customizations.

Continue reading

Alexey Sapozhnikov liked this post

## Solving a Matlab MCOS bug

A few days ago, one of my consulting clients asked me to help him with a very strange problem: he had a Matlab class having a `constant`

property that holds a reference to some handle class object. The problem was that when he tried to modify the property’s inner values he got Matlab run-time errors because the inner value apparently remained unmodified!

Here is a distilled version of my client’s classes:

classdef (Abstract) MainClass properties (Constant) inner = InnerClass end methods (Static) function setInnerValue(newValue) MainClass.inner.value1 = newValue; end end end classdef InnerClass < handle properties value1 value2 end end

And the strange run-time behavior:

>> MainClass.inner.value1 = 5 MainClass = inner: [1x1 struct] >> MainClass.inner.value2 % causes a strange run-time error! Reference to non-existent field 'value2'. >> MainClass.inner.value1 % strange - value1 appears unmodified! ans = [] >> MainClass.inner % strange - value1 appears ok here, but where is value2 ?! ans = value1: 5 >> MainClass.setInnerValue(7) % another strange run-time error! Reference to non-existent field 'setInnerValue'. >> clear classes % let's try it afresh... >> MainClass.setInnerValue(7) % looks ok, no error... >> MainClass.inner % strange - now we have both value1 & value2, but value1 is not updated! ans = InnerClass with properties: value1: [] value2: [] >> MainClass.inner.value1 = 9 % one last attempt, that also fails! MainClass = inner: [1x1 struct] >> MainClass.inner ans = InnerClass with properties: value1: [] value2: [] >> MainClass.inner.value1 ans = []

### Understanding the [buggy?] behavior

What the heck is going on here? did Matlab’s MCOS flip its lid somehow? Well, apparently not. It turns out that all these strange behaviors can be attributed to a single Matlab oddity (I call it a “bug”) in its class object system (MCOS) implementation. Understanding this oddity/bug then leads to a very simply workaround.

Continue reading

## Customizing contour plots

One of my clients asked me last week whether it is possible to access and customize individual contour lines and labels in HG2 (Matlab’s new graphics system, R2014+). Today’s post will discuss how this could indeed be done.

In HG1 (R2014a and earlier), contour handles were simple`hggroup`

objects that incorporated `text`

and `patch`

child handles. The contour labels, lines and fill patches could easily be accessed via these child handles (contour lines and fills use the same patch object: the lines are simply the patch edges; fills are their faces). The lines could then be customized, the label strings changed, and the patch faces (fills) recolored:[X,Y,Z] = peaks; [C,hContour] = contour(X,Y,Z,20, 'ShowText','on'); hChildren = get(hContour, 'Children'); set(hChildren(1), 'String','Yair', 'Color','b'); % 1st text (contour label) set(hChildren(end), 'EdgeColor',[0,1,1]); % last patch (contour line)

The problem is that in HG2 (R2014b onward), * contour* (and its sibling functions,

*etc.) return a graphic object that has no accessible children. In other words,*

**contourf**`hContour.Children`

returns an empty array:>> hContour.Children ans = 0x0 empty GraphicsPlaceholder array. >> allchild(hContour) ans = 0x0 empty GraphicsPlaceholder array. >> isempty(hContour.Children) ans = 1

So how then can we access the internal contour patches and labels?

Continue reading

## Figure keypress modifiers

Matlab figures have a documented property called **SelectionType** that returns information about keypress modifiers such as

- The reported
**SelectionType**value is`'extend'`

for shift-clicks and`'alt'`

for ctrl-clicks, not very intuitive. - There is no support for alt-clicks, which are reported as regular (
`'normal'`

) mouse clicks. In fact,`'alt'`

is reported for ctrl-clicks rather than for alt-clicks, which is very confusing. - There is no support for modifier combinations such as ctrl+shift-click. These again are reported as regular (
`'normal'`

) mouse clicks. **SelectionType**is only updated for mouse clicks, not for keyboard clicks. This again is very confusing. To extract the keypress modifier for key-click events we need to get the**Modifier**property of the key-press event, and this returns a cell-array of strings (e.g.,`{'shift','control','alt'}`

). Note that in this case, unlike**SelectionType**, the modifier names are as expected, alt-clicks is recognised and so are modifier combinations.

% Documented: we need to get the modifier data in two different manners set(gcf, 'WindowButtonDownFcn', @(h,e) disp(get(gcf,'SelectionType'))); % mouse clicks: displays a single string: 'normal','alt','extend' or 'open' set(gcf, 'WindowKeyPressFcn', @(h,e) disp(e.Modifier)); % keyboard clicks: displays a cell-array of strings, e.g. {'shift','control','alt'}

The inconsistency between the functionality for mouse and keyboard clicks, and the limitations of the **SelectionType** property, are striking and most annoying. Some might say that it’s been like this for the past 2 decades so Matlab users have probably gotten used to it by now. But I must admit that after over 2 decades with Matlab I still need to refer to the documentation to figure out the correct behavior. Maybe that’s because I’m getting old, or maybe it means that the behavior is indeed not as intuitive as one could hope for.

For this reason, I was very happy to discover several years ago that there was a much simpler, easier and consistent solution, although (alas) undocumented. The trick is to simply query the undocumented hidden figure property **CurrentModifier**: Continue reading

## Hyperlink text labels

It is often useful to include hyperlinked text labels in GUIs. Such labels provide single-click access to important functionality, improve branding, and are non-intrusive action controls having a lower visual impact than a full-blown button. There are several ways that we can display such hyperlinks in Matlab GUIs, and today I will show one of my favorites.

The basic idea is to create a Java text label control whose label displays an HTML link. The control is modified to change the mouse cursor when it hovers over the hyperlink, and a mouse-click callback is set to open the hyperlink target in the system browser:

% Create and display the text label url = 'UndocumentedMatlab.com'; labelStr = ['<html>More info: <a href="">' url '</a></html>']; jLabel = javaObjectEDT('javax.swing.JLabel', labelStr); [hjLabel,hContainer] = javacomponent(jLabel, [10,10,250,20], gcf); % Modify the mouse cursor when hovering on the label hjLabel.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR)); % Set the label's tooltip hjLabel.setToolTipText(['Visit the ' url ' website']); % Set the mouse-click callback set(hjLabel, 'MouseClickedCallback', @(h,e)web(['http://' url], '-browser'))

Categories: GUI, Java, Low risk of breaking in future versions

Tags: GUI, Java, Undocumented function

2 Comments

Tags: GUI, Java, Undocumented function

2 Comments