- Enclose with " for exact match e.g., "uitable report"
- Plot markers transparency and color gradient
- Plot line transparency and color gradient
- Customizing axes part 4 – additional properties
- Customizing axes part 3 – Backdrop
- Customizing axes part 2
- Customizing axes rulers
- Customizing combobox popups
- Customizing listbox/combobox items
- savezip utility
- Inter-Matlab data transfer with memcached
- Property value change listeners
- Online (web-based) Matlab
- Class object tab completion & improper field names
- Using pure Java GUI in deployed Matlab apps
- Desktop (34)
- Figure window (34)
- Guest bloggers (43)
- GUI (113)
- Handle graphics (58)
- Hidden property (32)
- Icons (7)
- Java (136)
- Listeners (17)
- Memory (12)
- Mex (9)
- Presumed future risk (273)
- Semi-documented feature (7)
- Semi-documented function (31)
- Stock Matlab function (102)
- Toolbox (2)
- UI controls (39)
- Uncategorized (9)
- Undocumented feature (133)
- Undocumented function (29)
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 Matt Whitaker MCOS Memory Menubar Mex 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
- Yair Altman (2 days 4 hours ago): @Christopher – this is because the flat header is used by the new (R2008a+) uitable, whereas the gradient-colored header is used by the “old” uitable...
- Yair Altman (2 days 4 hours ago): A lot of things broke in R2014b due to the replacement of the graphics engine in this release (HG2). There’s probably a new way to do the same functionality in HG2, but I...
- HongKee Yoon (2 days 13 hours ago): @ 2014b this dose not works. Is there any solution to this??
- Christopher (2 days 18 hours ago): In the: Creating multi-line headers section, you have two examples, the first having the flat default matlab tan color on the headers,.. the other has a ’rounded’...
- Paul (3 days 6 hours ago): Thanks, this is useful — setting an alpha component is a better way to visualise density than applying jitter.
- Yair Altman (5 days 22 hours ago): @Gang – there’s a BaseValue property (value=0), but changing it apparently has no effect (at least in R2014b). Maybe this will be fixed in future Matlab releases. Re...
- Yair Altman (5 days 23 hours ago): @Kris – I already answered this above. jFrame = get(handle(hFig), 'JavaFrame'); jFrame.fHG2Client.getWindow.se tEnabled(flag);
- Kris Janssen (6 days 0 hours ago): Hello Yair, I recently took Matlab 2014b for a spin and browsing the Matlab Jar files I found that most of the stuff in com.mathworks.hg.peer is now private or protected....
- Yaroslav (6 days 21 hours ago): That’s absolutely splendid, @Yair! All those years I used a 2×N mesh in order to make a gradient plot, and it turns out to be so simple in HG2. Keep up the good work!
- Jveer (7 days 5 hours ago): @Yair Thanks for the suggestion but ‘drawnow; pause(0.2);’ didn’t work. I did figure it out though. It turns out findobj is creating 6 handles instead of 1...
- Yair Altman (7 days 20 hours ago): @Paul – I plan to cover Marker customizations (including transparency) in next week’s post. Stay tuned
- Paul (8 days 21 hours ago): Have you managed to get the same working for markers? I can’t set the alpha component for MarkerFaceColor, and setting it for Color doesn’t even affect the marker edge: >>...
- Yair Altman (9 days 1 hour ago): @JVeer – it works for me on R2014b (Win7 x64) in the command prompt… I suspect that either your editbox or its containing figure is hidden (in which case findjobj...
- Jveer (9 days 1 hour ago): Hi Yair This functionality seems to break down in R2104b. (I’m using the latest findjobj btw). No appropriate method, property, or field getViewport for class handle.handle....
- Sebastian (10 days 0 hours ago): Yair, thanks for your reply. I’ve tried with your fanstastic uiinspect() function but I was not able to find anything interesting. What I mean is, imagine you have the...
Last week I explained how to customize plot-lines with transparency and color gradient. Today I wish to show how we can achieve similar effects with plot markers. Note that this discussion (like the preceding several posts) deal exclusively with HG2, Matlab’s new graphics system starting with R2014b (well yes, we can also turn HG2 on in earlier releases).
As Paul has noted in a comment last week, we cannot simply set a 4th (alpha transparency) element to the MarkerFaceColor and MarkerEdgeColor properties:
>> x=1:10; y=10*x; hLine=plot(x,y,'o-'); >> hLine.MarkerFaceColor = [0.5,0.5,0.5]; % This is ok >> hLine.MarkerFaceColor = [0.5,0.5,0.5,0.3]; % Not ok While setting the 'MarkerFaceColor' property of Line: Color value must be a 3 element numeric vector
Lost cause? – not in a long shot. We simply need to be a bit more persuasive, using the hidden MarkerHandle property:
In the past few weeks, I discussed the new HG2 axes Backdrop and Baseline properties with their associated ability to specify the transparency level using a fourth (undocumented) element in their Color.
In other words, color in HG2 can still be specified as an RGB triplet (e.g., [1,0,0] to symbolize bright red), but also via a 4-element quadruplet RGBA, where the 4th element (Alpha) signifies the opacity level (0.0=fully transparent, 0.5=semi-transparent, 1.0=opaque). So, for example, [1, 0, 0, 0.3] means a 70%-transparent red.
This Alpha element is not documented anywhere as being acceptable, but appears to be supported almost universally in HG2 wherever a color element can be specified. In some rare cases (e.g., for patch objects) Matlab has separate Alpha properties that are fully documented, but in any case nowhere have I seen documented that we can directly set the alpha value in the color property, especially for objects (such as plot lines) that do not officially support transparency. If anyone finds a documented reference anywhere, please let me know – perhaps I simply missed it.
Here is a simple visualization:
xlim([1,5]); hold('on'); h1a = plot(1:5, 11:15, '.-', 'LineWidth',10, 'DisplayName',' 0.5'); h1b = plot(1.5:5.5, 11:15, '.-', 'LineWidth',10, 'DisplayName',' 1.0', 'Color',h1a.Color); % 100% opaque h1a.Color(4) = 0.5; % 50% transparent h2a = plot(3:7, 15:-1:11, '.-r', 'LineWidth',8, 'DisplayName',' 0.3'); h2a.Color(4)=0.3; % 70% transparent h2b = plot(2:6, 15:-1:11, '.-r', 'LineWidth',8, 'DisplayName',' 0.7'); h2b.Color(4)=0.7; % 30% transparent h2c = plot(1:5, 15:-1:11, '.-r', 'LineWidth',8, 'DisplayName',' 1.0'); % 100% opaque = 0% transparent legend('show','Location','west')
Now for the fun part: we can make color-transition (gradient) effects along the line, using its hidden Edge property:
In the past three weeks I explained how HG2 (in R2014b) enables us to customize the axes rulers, back-drop, baselines, box and grid-lines in ways that were previously impossible in HG1 (R2014a or earlier). Today I will conclude the mini-series on axes customizations by describing other useful undocumented customizations of the HG2 axes:
In the past two weeks I explained how HG2 (in R2014b) enables us to customize the axes rulers, baselines, box and grid-lines in ways that were previously impossible in HG1 (R2014a or earlier). Today I will describe another useful undocumented property of the HG2 axes – Backdrop.
Last week I explained how HG2 (in R2014b) enables us to customize the axes rulers in ways that were previously impossible in HG1 (R2014a or earlier). Today I will describe other useful undocumented customizations of the HG2 axes:
Over 4 years have passed since I’ve posted my scoop on Matlab’s upcoming new graphics system (a.k.a. HG2, Handle Graphics version 2). At that time HG2 was still far from usable, but that has changed when I posted my HG2 update last year. Numerous user feedbacks, by email and blog comments, were reported and the MathWorks developers have listened and improved the code. HG2 was finally released with Matlab R2014b last Friday, and it seems at first glance to be a beauty. I hope my posts and the feedbacks have contributed, but in any case the MathWorks dev group deserves big kudos for releasing a totally new system that provides important usability and aesthetic improvements [almost] without sacrificing performance or backward-compatibility. Trust me, it’s not an easy achievement.
One of the nice things that I like about HG2 is that it provides numerous new ways to customize the objects in ways that were impossible (or nearly so) in the old HG1. In R2014b, the leap was large enough that MathWorks wisely chose to limit the official new properties to a bare minimum, for maximal HG1 compatibility. I assume that this will remain also in R2015a, which I expect to be a release devoted to bug fixing and stabilization rather than to new features. I expect the new features to start becoming official in R2015b onward. Such a measured roadmap is to be expected from a responsible engineering company such as MathWorks. So in fact there is no need at all to be disappointed at the relative lack of new functional features. They are all there already, just not yet official, and this is just as it should be.
That being said, if we are aware of the risk that these features might change in the upcoming years until they become official (if ever), then we can start using them today. Experience with this blog has shown that the vast majority of such undocumented features remain working unchanged for years, and some of them eventually become documented. For example, uitab/uitabgroup, on which I posted over 4 years ago, and which has existed almost unchanged since 2005, finally became official in R2014b after many years of running in unofficial form.
In the next few weeks I intend to present a series of posts that highlight some of the undocumented customizations in HG2. I’ll start with some new axes features, followed by plotting aspects.
Last week I explained how we can use display custom items in a standard Matlab combobox (popup/dropdown), using its underlying Java component. Today I will show how we can use this Java component for other nice customizations of the combobox’s popup:
Last week I wrote about using a variety of techniques to customize listbox items with an attached checkbox icon. Some of these methods used a standard Matlab listbox uicontrol, others used other controls. Today I wish to extend the discussion and show how Matlab listbox and combobox (pop-up) items can be customized in a variety of ways.
To add icons to listbox/combobox items, we could use standard HTML, as I’ve shown last week. This is the simplest method, requires no Java knowledge, and it usually works well. The problem is that when a listbox/combobox has numerous items (hundreds or more), it may start getting sluggish. In such case it is faster to use a dedicated Java cell-renderer that sets the icon, font, colors, tooltip and other aspects on an item-by-item basis. This runs faster and enables far greater customizability than what is possible with HTML. The drawback is that it requires some Java programming. No free lunch…
Listbox and combobox cell-renderers need to extend
javax.swing.ListCellRenderer, similarly to uitable cell-renderers. This is basically a simple Java class that minimally contains just an empty constructor and a getListCellRendererComponent() method with a predefined signature. getListCellRendererComponent() is automatically called by the Swing render engine separately for each listbox item, and gets as input args a
JList reference, the item value (typically a string), an integer list index, a boolean flag indicating whether the item is currently selected, and another flag indicating whether the item is currently in focus. getListCellRendererComponent() uses these parameters to customize and return a
java.awt.Component, which is typically (but not necessarily) a standard Swing
Here is a simple example that displays a folder of icon files in a Matlab listbox and combobox. Each item is the filename, with a customization that if the file is an icon, then this icon is displayed next to the file name, otherwise the name appears in red italic without an icon. For illustration, we’ll use Matlab’s builtin icons folder: %matlabroot%/toolbox/matlab/icons/:
Several years ago I blogged about using a checkbox-tree in Matlab. A few days ago there was a question on the Matlab Answers forum asking whether something similar can be done with Matlab listboxes, i.e. add checkboxes next to each list item. There are actually several alternatives for this and I thought this could be a good opportunity to discuss them:
- The HTML image variant
- MathWorks CheckBoxList
- JIDE’s CheckBoxList
- ActiveX and other alternatives
- Matlab uitable in disguise
A few months ago I wrote about Matlab’s undocumented serialization/deserialization functions, getByteStreamFromArray and getArrayFromByteStream. This could be very useful for both sending Matlab data across a network (thus avoiding the need to use a shared file), as well as for much faster data-save using the -V6 MAT format (save -v6 …).
As a followup to that article, in some cases it might be useful to use ZIP/GZIP compression, rather than Matlab’s proprietary MAT format or an uncompressed byte-stream.
Unfortunately, Matlab’s compression functions zip, gzip and tar do not really help run-time performance, but rather hurt it. The reason is that we would be paying the I/O costs three times: first to write the original (uncompressed) file, then to have zip or its counterparts read it, and finally to save the compressed file. tar is worst in this respect, since it does both a GZIP compression and a simple tar concatenation to get a standard tar.gz file. Using zip/gzip/tar only makes sense if we need to pass the data file to some external program on some remote server, whereby compressing the file could save transfer time. But as far as our Matlab program’s performance is concerned, these functions bring little value.
In contrast to file-system compression, which is what zip/gzip/tar do, on-the-fly (memory) compression makes more sense and can indeed help performance. In this case, we are compressing the data in memory, and directly saving to file the resulting (compressed) binary data. The following example compresses int8 data, such as the output of our getByteStreamFromArray serialization: