Comments for Undocumented Matlab Charting Matlab's unsupported hidden underbelly Sun, 15 Jan 2017 11:30:17 +0000 hourly 1 Comment on cprintf – display formatted color text in the Command Window by Yair Altman Sun, 15 Jan 2017 11:30:17 +0000 Not as far as I know…

Comment on cprintf – display formatted color text in the Command Window by MolaRam Sun, 15 Jan 2017 10:25:59 +0000 Hello Yair,
is it possible to set the text background color as well (not for the whole command window)?

Comment on Sliders in Matlab GUI by Yair Altman Sat, 14 Jan 2017 16:35:06 +0000 @Misha – you can add the relevant code snippets (with the javacomponent call) to your *_OutputFcn() function that is created by GUIDE in your main m-file. Pass the panel’s handle as the 3rd input arg to javacomponent. See my post on javacomponent for details.

Comment on Sliders in Matlab GUI by Misha Fri, 13 Jan 2017 23:38:55 +0000 Dear Yair,
Thank you for all the wonderful tips!
The sliders work as advertised, but I would like to be able to add a jSlider to an already existing GUI created using the GUIDE. More specifically, since the GUI is resizable, I would like make it so that upon creation, the slider be attached to a particular panel, so that the proportions are preserved window is being resized. Is there a way to do that? Thanks in advance.

Comment on Quirks with parfor vs. for by Gabriele Wed, 11 Jan 2017 09:12:00 +0000 Please, let me come back on this interesting matter.

After some checks, I think it could be a matter associated with loss of significance in case of calculations (like std, mean, sum, etc.) which involve summing up relatively small numbers (here we are randomly generating from U(0,1)) to (partial) summations which are large with respect to the available precision.

In case of multi-thread computations, since the summations are (likely) carried out in separate pieces, the effect is seen “later” in terms of dimension of the array under analysis. Instead, in single-thread calculations this is seen “before”.

I have prepared a script + a function which might be useful to show this effect (I used R2016a – change the first switch to change the test function):

— Script —

switch 1, %change the function here
    case 1, %STD
        f=@(x) std(x); %function to be evaluated
    case 2, %MEAN
        f=@(x) mean(x); %function to be evaluated
    case 3, %SUM
        f=@(x) sum(x); %function to be evaluated
NTO = maxNumCompThreads; %number of threads in console - it is assumed that NTO>1
Nd = 5*10^7; %Number of data - At least abt 4*10^7 is needed to see the problem in my case. Be very careful with RAM limitations (try smaller values first, and then increase progressively)! 
arr_double = rand(1,Nd);
arr_single = single(arr_double);
ind = round(linspace(100,Nd,100));
f_double_MT = f_test_progressive(f,ind,arr_double);
f_single_MT = f_test_progressive(f,ind,arr_single);
%go to single thread:
f_double_ST = f_test_progressive(f,ind,arr_double);
f_single_ST = f_test_progressive(f,ind,arr_single);
%go back to original number of threads:
%now use a parfor:
[f_double_PF, f_single_PF] = deal(cell(1));
parfor i = 1
    f_double_PF{i} = f_test_progressive(f,ind,arr_double);
    f_single_PF{i} = f_test_progressive(f,ind,arr_single);    
f_double_PF = f_double_PF{1};
f_single_PF = f_single_PF{1};
hold all;
plot(ind,f_double_MT,'-o', 'Displayname','Double-MT');
plot(ind,f_double_ST,'-s', 'Displayname','Double-ST');
plot(ind,f_double_PF,'-d', 'Displayname','Double-PF');
xlabel('Progressive index - i');

— End script —

— Support function —

function out = f_test_progressive(fh,ind,x)
   ind = unique(ind);
   Ntest = numel(ind);
   switch class(x),
      case 'double',  out = nan(1,Ntest);
      case 'single',  out = single(nan(1,Ntest));
      otherwise,      error('f_test_progressive:ErrorDataType','Data type not allowed');                
   for jt=1:Ntest
      out(jt) = fh(x(1:ind(jt)));

— End support function —

Basically a function specified by handle “fh” (first switch) is calculated on the first ind(jt) elements of the array, considering single/double precision, and single-/multi-thread, as well as parfor (by default single-thread).

In my case, with single-thread, I see the issue occurring particularly with single-precision, single-thread calculations. It is interesting to see how the effect is different depending on the specific function which is evaluated. “std”, in my case, is particularly problematic, while “mean” and “sum” in single-precision/single-thread basically agree with double precision results up to a dimension of about 3.3e7 (in my case).

I hope it can be useful.

Comment on Quirks with parfor vs. for by Gabriele Mon, 09 Jan 2017 13:16:05 +0000 Thanks for the very useful post!

Perhaps I’m wrong, but it seems to be something related to intrinsic parallelization combined with single accuracy. In fact, as a basis, the main console is multi-thread. On the other hand workers are started, as a basis, using a single thread. Changing from multi-thread to single-thread computations in the console, I can reproduce the issue you have identified with parfor.

This example reproduces the issue from within the console:

NTO = maxNumCompThreads; %number of threads in console - it is assumed that NTO>1
arr_double = rand(1,10000000*5);
arr_single = single(arr_double);
std_double_MT = std(arr_double);
std_single_MT = std(arr_single);
%go to single thread:
std_double_ST = std(arr_double);
std_single_ST = std(arr_single);
%go back to original number of threads:
%now use a parfor:
std_double_PF = NaN;
std_single_PF = NaN;
parfor i=1
    std_double_PF(i) = std(arr_double);
    std_single_PF(i) = std(arr_single);
fprintf('\n\nResults from console with intrinsic parallelization (multi-thread):');
fprintf('\n\nResults from console with single thread:');
fprintf('\n\nResults from parfor:');
fprintf('\n\nAnalytical result:');
fprintf('\n       std_an=%f',sqrt(1/12));


Outcome in my case (I have NTO=4):

Results from console with intrinsic parallelization (multi-thread):
Results from console with single thread:
Results from parfor:
Analytical result:
Comment on Solving a Matlab hang problem by g. Sun, 08 Jan 2017 16:34:24 +0000 Hi,

I have a similar problem under Linux, Ubuntu 16.04. Matlab hangs up when using the “print” command to export figures. I can not interrupt the software and I have to kill the process.

My script makes simple 3d graphics and uses some additional functions written by me. What is weird is that the problem is systematic, however, the same functions, used to generate other plots, do not causes any problem. The problem arises with the print command, no matter the option used. Matlab goes in “Busy” state but it allows me to, e.g., edit the script.

I tried to add before/after the print command the pause and/or drawnow commands but without success as suggested here (.

uname -a
Linux laresa 4.4.0-57-generic #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

MATLAB Version: (R2014a)
MATLAB License Number: ••••••
Operating System: Linux 4.4.0-57-generic #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode

Any help is welcome g.

Comment on Simulink Data Dictionary by Donn Shull Sat, 07 Jan 2017 16:03:47 +0000 Hi Matt,

To my knowledge the answer is no. In the automotive world there is a system for doing what you describe. It is fairly complex and based around a closed set of standards from the group “Association for Standardisation of Automation and Measuring Systems”. You can read about the group at One of the motivations for the creation of Simulink Data Objects and the Simulink Data Dictionary was to support the creation of ASAP2 variable description files. These ASAM ASAP2 files along with ASAM CDF (Calibration Data Format) files provide the mechanism that calibration engineers use to read measurements from an embedded control system and to do the thing you describe providing initial values for constants and tuning values of other constants during operation.

The idea that you propose is interesting rather than parsing a config file it would be nice to use api commands to extract the values from a data dictionary file. I am not sure why The MathWorks has kept the Data Dictionary implementation under wraps. It seems very likely that under the hood it is very likely an embedded database along the lines of MySql Embedded or SqLite. If you could get that information from The MathWorks then it seems that it would be reasonably easy to do what you are asking.

If you find out more please let us know.


Comment on Quirks with parfor vs. for by Yair Altman Sat, 07 Jan 2017 15:58:12 +0000 @James – the entire point of using parfor is not to use a single computation thread but rather run in parallel over multiple workers. The code in the article was simply illustrating this point using a single loop iteration, but the problem itself is also evident in multi-workers processing multi-iteration loops. In all cases one would reasonably expect Matlab to return numerically accurate results.

Comment on Quirks with parfor vs. for by Xiangrui Li Sat, 07 Jan 2017 15:51:49 +0000 It seems a serious bug. I tested mean instead of std, and the result is similar. Maybe the error for std is due to the error for mean?

I played with different sizes for arr_double: [2e7 5e7 8e7 1e8 2e8],
parforSingleAccuracy-1 gives following:
[0.0001 0.4901 1.3841 1.9798 0]

parforDoubleAccuracy-1 gives following:
[0.1350 0.1619 0.1648 0.4738 0] * 1e-12

The last (for size 2e8) is zero because it exceeds memory, and matlab gives a warning and switches to local computation.

Comment on Quirks with parfor vs. for by James Fri, 06 Jan 2017 15:10:21 +0000 Try again with -singleCompThread

Comment on Quirks with parfor vs. for by zed Fri, 06 Jan 2017 15:07:25 +0000 I had to deal with the parfor over object arrays ‘challenge’; when processing by invoking a method that operates on internal properties it doesn’t bother returning the properties. I think this is a bad bug, and a terrible oversight when they added both the new object concept and the parallel toolbox. I add an extra property called “returnVal” to the class to touch, then it does reliably return all of the properties.

parfor ii=1:10; q(ii).process; q(ii).returnVal=ii; end

I end up debugging this over and over though.


Comment on Simulink Data Dictionary by Matt Thu, 05 Jan 2017 18:56:46 +0000 Something I ran into recently was a need to provide runtime initialization of Simulink data parameter objects in a compiled application. I solved the issue by calling a config file parser in the hand coded portion of the models initialization function, and used the C-API interface to update the model parameters to match the values specified in the config file, but I really wanted to simply load a Simulink Data Dictionary instead as it seemed a very obvious use for them.

Have there been any hints of data dictionaries being natively usable in compiled models for anything besides compile-time initialization of data objects?

Comment on Plot line transparency and color gradient by Tom Sat, 31 Dec 2016 04:32:23 +0000 Unfortunately it seems that the legend cannot show the corresponding line as a gradient. The line color appears to match one end of the gradient. I tried a bungch of things but wasn’t able to change the lines in the legend to gradients to match the lines in the figure.

Comment on Graphic sizing in Matlab R2015b by Dan Dolan Fri, 30 Dec 2016 23:02:18 +0000 I posted a partial workaround on the Mathworks File Exchange.

Comment on Undocumented feature() function by Yair Altman Sun, 25 Dec 2016 16:50:42 +0000 @Kristian – yes, feature('OpenGLLoadStatus') works in R2015a. It would be interesting to know how you are using this feature – can you tell us?

Comment on Auto-completion widget by Yair Altman Fri, 23 Dec 2016 10:57:47 +0000 @Stefano – answering this is beyond the time that I can spend on a blog comment. You’re invited to email me (altmany at gmail) for a short consultancy on your specific program.

Comment on treeTable by Yair Altman Fri, 23 Dec 2016 10:52:55 +0000 @Daniele – that code snippet is not connected to the main program, it was just illustrative (as in pseudo-code). SortableTreeTableModel does not have a removeRow method, but the underlying data model (a TreeTableModel object, accessible via jtable.getModel.getActualModel) does.

Comment on treeTable by Daniele F. Fri, 23 Dec 2016 10:23:48 +0000 Dear Yair,
First of all, thanks for this great tool.
Second: I’m not a Java user

At the end of your code you written some sample functions.
I wanted to use the %% Sample row deletion function.
So I tried the command:


but what I get is:

Undefined function 'removeRow' for input arguments of
type 'com.jidesoft.grid.SortableTreeTableModel'.

More than this, if I look into:
I don’t find any reference to the method removeRow

Is the removeRow function obsolete or am I, most probably, doing something wrong?

Kind regards

Comment on Auto-completion widget by Stefano Thu, 22 Dec 2016 09:47:19 +0000 Hi Yair,

I’m trying to implement your Autocomplete widget in my GUI (more simple than yours).
I’ve decided to split the code to better understand it, but i have two problems:

1) I can’t select the word from the combobox dropdown panel or by typing in the search text-box

How can i do that? How can i get the selected word to use it?
I’ve tried with jAssetChooser.getSearchText or jCombo.getSelectedItem but it didn’t work.
Must i use the setappdata comand?

2) If the word doesn’t match with my the list i get this Java error:

Error using provaaa/updateSearch (line 94)
Java exception occurred:
	at javax.swing.DefaultComboBoxModel.(Unknown Source)

I’m using matlab 2016a.

This is my example code:
[*** very large code section removed ***]

Thanks in advance.