Comments for Undocumented Matlab http://undocumentedmatlab.com Charting Matlab's unsupported hidden underbelly Sun, 15 Jan 2017 11:30:17 +0000 hourly 1 https://wordpress.org/?v=4.4.1 Comment on cprintf – display formatted color text in the Command Window by Yair Altmanhttp://undocumentedmatlab.com/blog/cprintf-display-formatted-color-text-in-command-window#comment-398686 Sun, 15 Jan 2017 11:30:17 +0000 http://undocumentedmatlab.com/?p=274#comment-398686 Not as far as I know…

]]>
Comment on cprintf – display formatted color text in the Command Window by MolaRamhttp://undocumentedmatlab.com/blog/cprintf-display-formatted-color-text-in-command-window#comment-398683 Sun, 15 Jan 2017 10:25:59 +0000 http://undocumentedmatlab.com/?p=274#comment-398683 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 Altmanhttp://undocumentedmatlab.com/blog/sliders-in-matlab-gui#comment-398657 Sat, 14 Jan 2017 16:35:06 +0000 http://undocumentedmatlab.com/?p=5827#comment-398657 @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 Mishahttp://undocumentedmatlab.com/blog/sliders-in-matlab-gui#comment-398645 Fri, 13 Jan 2017 23:38:55 +0000 http://undocumentedmatlab.com/?p=5827#comment-398645 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 Gabrielehttp://undocumentedmatlab.com/blog/quirks-with-parfor-vs-for#comment-398542 Wed, 11 Jan 2017 09:12:00 +0000 http://undocumentedmatlab.com/?p=6821#comment-398542 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 —

clear
rng('shuffle','twister');
 
switch 1, %change the function here
    case 1, %STD
        f=@(x) std(x); %function to be evaluated
        fname='std(x(1:i))';
    case 2, %MEAN
        f=@(x) mean(x); %function to be evaluated
        fname='mean(x(1:i))';
    case 3, %SUM
        f=@(x) sum(x); %function to be evaluated
        fname='sum(x(1:i))';        
end
 
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:
maxNumCompThreads(1);
 
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:
maxNumCompThreads(NTO);
 
%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);    
end
f_double_PF = f_double_PF{1};
f_single_PF = f_single_PF{1};
 
figure;
hold all;
plot(ind,f_double_MT,'-o', 'Displayname','Double-MT');
plot(ind,f_single_MT,'--o','Displayname','Single-MT');
plot(ind,f_double_ST,'-s', 'Displayname','Double-ST');
plot(ind,f_single_ST,'--s','Displayname','Single-ST');
plot(ind,f_double_PF,'-d', 'Displayname','Double-PF');
plot(ind,f_single_PF,'--d','Displayname','Single-PF');
xlabel('Progressive index - i');
ylabel(fname);
legend('Location','Best');

— 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');                
   end
 
   for jt=1:Ntest
      out(jt) = fh(x(1:ind(jt)));
   end
end

— 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.
Gabriele

]]>
Comment on Quirks with parfor vs. for by Gabrielehttp://undocumentedmatlab.com/blog/quirks-with-parfor-vs-for#comment-398474 Mon, 09 Jan 2017 13:16:05 +0000 http://undocumentedmatlab.com/?p=6821#comment-398474 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:

clear
rng('shuffle','twister');
 
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:
maxNumCompThreads(1);
 
std_double_ST = std(arr_double);
std_single_ST = std(arr_single);
 
%go back to original number of threads:
maxNumCompThreads(NTO);
 
%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);
end;
 
fprintf('\n\nResults from console with intrinsic parallelization (multi-thread):');
fprintf('\nstd_double_MT=%f',std_double_MT);
fprintf('\nstd_single_MT=%f',std_single_MT);
 
fprintf('\n\nResults from console with single thread:');
fprintf('\nstd_double_ST=%f',std_double_ST);
fprintf('\nstd_single_ST=%f',std_single_ST);
 
fprintf('\n\nResults from parfor:');
fprintf('\nstd_double_PF=%f',std_double_PF);
fprintf('\nstd_single_PF=%f',std_single_PF);
 
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):
std_double_MT=0.288674
std_single_MT=0.286997
 
Results from console with single thread:
std_double_ST=0.288674
std_single_ST=0.309665
 
Results from parfor:
std_double_PF=0.288674
std_single_PF=0.309665
 
Analytical result:
       std_an=0.288675
]]>
Comment on Solving a Matlab hang problem by g.http://undocumentedmatlab.com/blog/solving-a-matlab-hang-problem#comment-398454 Sun, 08 Jan 2017 16:34:24 +0000 http://undocumentedmatlab.com/?p=3617#comment-398454 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

ver
—————————————————————————————————-
MATLAB Version: 8.3.0.532 (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 Shullhttp://undocumentedmatlab.com/blog/simulink-data-dictionary#comment-398425 Sat, 07 Jan 2017 16:03:47 +0000 http://undocumentedmatlab.com/?p=5571#comment-398425 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 http://asam.net. 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.

Donn

]]>
Comment on Quirks with parfor vs. for by Yair Altmanhttp://undocumentedmatlab.com/blog/quirks-with-parfor-vs-for#comment-398424 Sat, 07 Jan 2017 15:58:12 +0000 http://undocumentedmatlab.com/?p=6821#comment-398424 @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 Lihttp://undocumentedmatlab.com/blog/quirks-with-parfor-vs-for#comment-398423 Sat, 07 Jan 2017 15:51:49 +0000 http://undocumentedmatlab.com/?p=6821#comment-398423 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 Jameshttp://undocumentedmatlab.com/blog/quirks-with-parfor-vs-for#comment-398390 Fri, 06 Jan 2017 15:10:21 +0000 http://undocumentedmatlab.com/?p=6821#comment-398390 Try again with -singleCompThread

]]>
Comment on Quirks with parfor vs. for by zedhttp://undocumentedmatlab.com/blog/quirks-with-parfor-vs-for#comment-398389 Fri, 06 Jan 2017 15:07:25 +0000 http://undocumentedmatlab.com/?p=6821#comment-398389 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.

–zed.

]]>
Comment on Simulink Data Dictionary by Matthttp://undocumentedmatlab.com/blog/simulink-data-dictionary#comment-398363 Thu, 05 Jan 2017 18:56:46 +0000 http://undocumentedmatlab.com/?p=5571#comment-398363 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 Tomhttp://undocumentedmatlab.com/blog/plot-line-transparency-and-color-gradient#comment-398203 Sat, 31 Dec 2016 04:32:23 +0000 http://undocumentedmatlab.com/?p=5200#comment-398203 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 Dolanhttp://undocumentedmatlab.com/blog/graphic-sizing-in-matlab-r2015b#comment-398193 Fri, 30 Dec 2016 23:02:18 +0000 http://undocumentedmatlab.com/?p=6244#comment-398193 I posted a partial workaround on the Mathworks File Exchange.

http://www.mathworks.com/matlabcentral/fileexchange/60953-scaled-figure-class

]]>
Comment on Undocumented feature() function by Yair Altmanhttp://undocumentedmatlab.com/blog/undocumented-feature-function#comment-397714 Sun, 25 Dec 2016 16:50:42 +0000 http://undocumentedmatlab.com/?p=1414#comment-397714 @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 Altmanhttp://undocumentedmatlab.com/blog/auto-completion-widget#comment-397448 Fri, 23 Dec 2016 10:57:47 +0000 http://undocumentedmatlab.com/?p=5763#comment-397448 @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 Altmanhttp://undocumentedmatlab.com/blog/treetable#comment-397447 Fri, 23 Dec 2016 10:52:55 +0000 http://undocumentedmatlab.com/?p=4062#comment-397447 @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.http://undocumentedmatlab.com/blog/treetable#comment-397440 Fri, 23 Dec 2016 10:23:48 +0000 http://undocumentedmatlab.com/?p=4062#comment-397440 Dear Yair,
First of all, thanks for this great tool.
Second: I’m not a Java user

Question:
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:

handles.jtable.getModel.removeRow(row)

but what I get is:

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

More than this, if I look into:
http://www.jidesoft.com/javadoc/com/jidesoft/grid/SortableTreeTableModel.html
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
Daniele

]]>
Comment on Auto-completion widget by Stefanohttp://undocumentedmatlab.com/blog/auto-completion-widget#comment-397242 Thu, 22 Dec 2016 09:47:19 +0000 http://undocumentedmatlab.com/?p=5763#comment-397242 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:
java.lang.NullPointerException
	at javax.swing.DefaultComboBoxModel.(Unknown Source)

I’m using matlab 2016a.

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

Thanks in advance.
Stefano

]]>