Comments for Undocumented Matlab https://undocumentedmatlab.com Charting Matlab's unsupported hidden underbelly Thu, 19 Jul 2018 21:33:29 +0000 hourly 1 https://wordpress.org/?v=4.4.1 Comment on Sliders in Matlab GUI – part 2 by Yair Altmanhttps://undocumentedmatlab.com/blog/sliders-in-matlab-gui-part-2#comment-432907 Thu, 19 Jul 2018 21:33:29 +0000 https://undocumentedmatlab.com/?p=7728#comment-432907 @Medi – I am not sure what you mean. I discussed a slider that has several knobs (“range slider”) here: https://undocumentedmatlab.com/blog/sliders-in-matlab-gui#range

]]>
Comment on Sliders in Matlab GUI – part 2 by medihttps://undocumentedmatlab.com/blog/sliders-in-matlab-gui-part-2#comment-432904 Thu, 19 Jul 2018 21:19:50 +0000 https://undocumentedmatlab.com/?p=7728#comment-432904 how can i plot many data with slider in Gui?

]]>
Comment on Plot legend customization by Yair Altmanhttps://undocumentedmatlab.com/blog/plot-legend-customization#comment-432760 Wed, 18 Jul 2018 07:58:49 +0000 https://undocumentedmatlab.com/?p=7744#comment-432760 @Peter – while the legend object’s ItemHitFcn callback property is documented/supported, the Item property of the eventData object (which is passed to the callback function in run-time when you click a legend entry) is indeed hidden/undocumented. This eventData.Item property contains the LegendEntry item that was clicked. Thanks for pointing it out.

]]>
Comment on Plot legend customization by Peter Cookhttps://undocumentedmatlab.com/blog/plot-legend-customization#comment-432669 Tue, 17 Jul 2018 15:17:11 +0000 https://undocumentedmatlab.com/?p=7744#comment-432669 I have recently incorporated the Legend’s ItemHitFcn callback property into a utility I built.
You can access and edit some relevant objects in the callback function, e.g.

hLegend.ItemHitFcn = myLegendItemHitFcn(src,evnt);
 
% The following in the callback function:
evnt.Peer %access line, patch, image, GraphPlot, etc... 
evnt.Item.Label %access text object for that legend entry
src.String{evnt.Item.Index} = 'new string'; %edit the legend entry name
]]>
Comment on ismembc – undocumented helper function by Yair Altmanhttps://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function#comment-432443 Sun, 15 Jul 2018 14:39:08 +0000 http://undocumentedmatlab.com/?p=164#comment-432443 @Rik – in a vast number of real-life use-cases, we already know in advance that either a or b or both are already sorted, and in this case ismembc is still faster than ismember, to this very day.
Even if you sort the arrays yourself (as in your 3rd usage example), ismembc is still much faster than ismember for most Matlab releases and almost as fast even on the latest release.
To make a long story short, there is very little (or no) down-side to using ismembc, at least from a performance viewpoint, as long as your inputs are non-sparse etc.

]]>
Comment on ismembc – undocumented helper function by Rik Wisselinkhttps://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function#comment-432439 Sun, 15 Jul 2018 13:01:12 +0000 http://undocumentedmatlab.com/?p=164#comment-432439 I’m sorry, I edited my code after I already pasted the code here and forgot to update the code along with the output. The remarks in the posted text still stand though. Below is a 20 iteration version along with the sum timings.

clc,n=2e6; a=ceil(n*rand(n,1)); b=ceil(n*rand(n,1)); d=sort(b);c=sort(a);
t_option=zeros(4,20);
for n_tic=1:size(t_option,2)
   tic; ismembc(c,d);              t_option(1,n_tic)=toc;
   tic; ismember(a,b);             t_option(2,n_tic)=toc;
   tic; ismembc(sort(a),sort(b));  t_option(3,n_tic)=toc;
   tic; ismembc(a,sort(b));        t_option(4,n_tic)=toc;
end
fprintf('%06.3f sec (pre-sorted a and b)\n',sum(t_option(1,:)));
fprintf('%06.3f sec (ismember)\n',          sum(t_option(2,:)));
fprintf('%06.3f sec (sort(a),sort(b))\n',   sum(t_option(3,:)));
fprintf('%06.3f sec (unsorted a,sort(b))\n',sum(t_option(4,:)));
%ML6.5
02.835 sec (pre-sorted a and b)
19.311 sec (ismember)
12.037 sec (sort(a),sort(b))
18.909 sec (unsorted a,sort(b))
 
%R2012b
02.415 sec (pre-sorted a and b)
14.289 sec (ismember)
05.581 sec (sort(a),sort(b))
14.176 sec (unsorted a,sort(b))
 
%R2018a
02.635 sec (pre-sorted a and b)
05.794 sec (ismember)
06.050 sec (sort(a),sort(b))
14.147 sec (unsorted a,sort(b))
]]>
Comment on ismembc – undocumented helper function by Yair Altmanhttps://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function#comment-432383 Sat, 14 Jul 2018 17:55:19 +0000 http://undocumentedmatlab.com/?p=164#comment-432383 @Rik – your outputs don’t correspond to your code, so they do not make any sense. Moreover, instead of reporting 3 separate timing instances, it would be better to report the total run-time of a loop of [say] 10-20 iterations.

]]>
Comment on ismembc – undocumented helper function by Rik Wisselinkhttps://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function#comment-432381 Sat, 14 Jul 2018 17:40:38 +0000 http://undocumentedmatlab.com/?p=164#comment-432381 @Yair, unfortunately, that is the same sample data as you use in your article. If you include the sort, ismembc becomes much slower to use. Interestingly, ismember on the older releases is similar to doing a sort of b and then calling ismembc, while in R2018a it has similar timings to a double sort before a call to ismembc. So sorting your own data is worth it (even with calling sort to an already sorted array, it is still faster than ismember).

clc,n=2e6; a=ceil(n*rand(n,1)); b=ceil(n*rand(n,1)); c=sort(b);d=sort(a);
tic;ismember(a,b);fprintf('%.3f sec, ',toc);
tic;ismember(a,b);fprintf('%.3f sec, ',toc);
tic;ismember(a,b);fprintf('%.3f sec (ismember)\n',toc);
tic;ismembc(a,sort(b));fprintf('%.3f sec, ',toc);
tic;ismembc(a,sort(b));fprintf('%.3f sec, ',toc);
tic;ismembc(a,sort(b));fprintf('%.3f sec (ismembc and sort)\n',toc);
tic;ismembc(a,c);fprintf('%.3f sec, ',toc);
tic;ismembc(a,c);fprintf('%.3f sec, ',toc);
tic;ismembc(a,c);fprintf('%.3f sec (ismembc, unsorted a)\n',toc);
tic;ismembc(d,c);fprintf('%.3f sec, ',toc);
tic;ismembc(d,c);fprintf('%.3f sec, ',toc);
tic;ismembc(d,c);fprintf('%.3f sec (ismembc, sorted a)\n',toc);

On my W10x64 machine this returns the following timings:

%ML6.5
0.137 sec, 0.139 sec, 0.138 sec (pre-sorted a and b)
0.896 sec, 0.901 sec, 0.909 sec (ismember)
0.582 sec, 0.582 sec, 0.578 sec (sort(a),sort(b))
0.865 sec, 0.862 sec, 0.866 sec (unsorted a,sort(b))
 
%R2012b
0.120 sec, 0.119 sec, 0.119 sec (pre-sorted a and b)
0.676 sec, 0.662 sec, 0.651 sec (ismember)
0.257 sec, 0.258 sec, 0.261 sec (sort(a),sort(b))
0.676 sec, 0.673 sec, 0.639 sec (unsorted a,sort(b))
 
%R2018a
0.127 sec, 0.124 sec, 0.123 sec (pre-sorted a and b)
0.249 sec, 0.248 sec, 0.256 sec (ismember)
0.287 sec, 0.272 sec, 0.289 sec (sort(a),sort(b))
0.664 sec, 0.676 sec, 0.664 sec (unsorted a,sort(b))
]]>
Comment on Plot legend customization by sco1https://undocumentedmatlab.com/blog/plot-legend-customization#comment-432282 Fri, 13 Jul 2018 01:40:39 +0000 https://undocumentedmatlab.com/?p=7744#comment-432282 Very interesting! I never explored NodeChildren when I was building legtools and was using PlotChildren instead to do things like rearrange the legend, add/remove entries, etc.

Have you had luck utilizing NodeChildren to perform similar options in MATLAB >= R2017a? R2017a introduced AutoUpdate to legend objects which broke pretty much all of the functionality I got from manipulating PlotChildren.

]]>
Comment on Sliders in Matlab GUI – part 2 by Yair Altmanhttps://undocumentedmatlab.com/blog/sliders-in-matlab-gui-part-2#comment-431809 Fri, 06 Jul 2018 11:29:27 +0000 https://undocumentedmatlab.com/?p=7728#comment-431809 @Zoltan – R2015b is 6 releases older than the latest Matlab release, so surely this is no surprise. New functions are being added to Matlab with each new release. If you upgrade to one of the latest Matlab releases you will be able to use this function.

]]>
Comment on Sliders in Matlab GUI – part 2 by Zoltan Csatihttps://undocumentedmatlab.com/blog/sliders-in-matlab-gui-part-2#comment-431807 Fri, 06 Jul 2018 11:18:40 +0000 https://undocumentedmatlab.com/?p=7728#comment-431807 In R2015b I only see the *+app*, the and the *+plot* packages inside the *+controllib* package, no *widget*.

]]>
Comment on String/char compatibility by Gelthhttps://undocumentedmatlab.com/blog/string-char-compatibility#comment-431793 Fri, 06 Jul 2018 09:16:33 +0000 https://undocumentedmatlab.com/?p=7710#comment-431793 @Yair,
1) Just precision : I just try the command controllib.internal.util.hString2Char(“”) (with matlab 2017b) and the result was 0×0 empty char array, not .
By looking the M-code, we see ” is reserved for empty string, BUT, “” is scalar String and then the code return char(“”), not ”.

2) Since I have problem with tcpip command (thread/ async pbwith big data stream to transfert over tcp) I look at the source code fo tcpip command. And I discover this command :
instrument.internal.stringConversionHelpers.str2char

Ok, it is in Instrument Toolbox, but if you have it, it seems best (more clear code than hString2Char because use of switch/case instead of if/then/else). Perhaps it should be a good option too.

]]>
Comment on Plot line transparency and color gradient by Ondrejhttps://undocumentedmatlab.com/blog/plot-line-transparency-and-color-gradient#comment-431667 Wed, 04 Jul 2018 10:09:04 +0000 http://undocumentedmatlab.com/?p=5200#comment-431667 Hi Yair,

I am trying to plot a line with a gradient which would be “perpendicular” to the line. For example:

N = 10;
p = plot(1:N, ones(1, N), ‘Linewidth’, 20);
cd = [uint8(jet(N)*255) uint8(ones(N, 1))].’;
drawnow
set(p.Edge, ‘ColorBinding’,’interpolated’, ‘ColorData’,cd)

This is a horizontal line with color gradient going from left to right (in the direction of the sample points). Is there a way to have a gradient going from top to bottom? (if the line is tilted, then the gradient would be still perpendicular to that line). The effect should look like the line is fading out in the perpendicular direction.

Thanks for any hints and ideas.

]]>
Comment on Animated busy (spinning) icon by Yair Altmanhttps://undocumentedmatlab.com/blog/animated-busy-spinning-icon#comment-431547 Mon, 02 Jul 2018 10:40:14 +0000 http://undocumentedmatlab.com/?p=4769#comment-431547 @Tobias – I do not have an immediate answer. You can easily open the Jar files (for example %matlabroot%/java/jar/mlwidgets.jar) using WinZip or WinRAR and check this. If you would like me to spend time to investigate this for you, then please contact me by email for private consulting.

]]>
Comment on Animated busy (spinning) icon by Tobiashttps://undocumentedmatlab.com/blog/animated-busy-spinning-icon#comment-431531 Mon, 02 Jul 2018 09:06:20 +0000 http://undocumentedmatlab.com/?p=4769#comment-431531 Hi,

I’m trying to use the ProgressBarDialog in Matlab R2018a. However, it seems to be missing from the com.mathworks.mlwidgets package.

Do you know if it has been removed completely or just renamed or moved to another package?

Thank you!

]]>
Comment on String/char compatibility by Yair Altmanhttps://undocumentedmatlab.com/blog/string-char-compatibility#comment-431487 Sun, 01 Jul 2018 14:06:03 +0000 https://undocumentedmatlab.com/?p=7710#comment-431487 Sam & David – I don’t want to pounce on the performance issue too much, after all my main point was about robustness and compatibility, not performance (which indeed is use-case dependent). But just for the record, please read Hanan’s recent comment about how repeated use of verLessThan turned out to be a performance bottleneck in his code.

]]>
Comment on String/char compatibility by Sam Robertshttps://undocumentedmatlab.com/blog/string-char-compatibility#comment-431359 Fri, 29 Jun 2018 16:22:41 +0000 https://undocumentedmatlab.com/?p=7710#comment-431359 Yair, note that there are cases where your doSomethingWith will itself slow down, just by virtue of being inside a try/catch block – for example, if it contains any in-place optimizations (which are disabled when run inside a try/catch block).

]]>
Comment on String/char compatibility by Davidhttps://undocumentedmatlab.com/blog/string-char-compatibility#comment-431353 Fri, 29 Jun 2018 14:03:19 +0000 https://undocumentedmatlab.com/?p=7710#comment-431353 You might want to rethink that statement about version 2 being faster. It’s only slightly faster in the new release where you are effectively doing a needless check. However, it’s a lot slower (total time in my example) in the old release where the error will occur inside the try/catch. If you are trying to support old releases as well then the try/catch could have just introduced a big performance degradation. Obviously all comes down to usecase.

%% Version 1
nThings = 1e4;
tic;
for iThing = 1:nThings
    if verLessThan('matlab', '9.1')
        % nothing to do in old release
    end
end
toc;
 
%% Version 2
tic;
for iThing = 1:nThings
    try
        % try to run function in old release which will error because it doesn't exist
        someFunctionThatWillErrorInOldRelease
    catch
    end
end
toc;
]]>
Comment on String/char compatibility by Yair Altmanhttps://undocumentedmatlab.com/blog/string-char-compatibility#comment-431336 Fri, 29 Jun 2018 11:25:40 +0000 https://undocumentedmatlab.com/?p=7710#comment-431336 David – I can understand where you’re coming from, but my experience with the code that I write is different. Consider the following code snippet for example:

% Version 1:
if someCondition()
   data = doSomethingWith(data);
else
   % do nothing in this specific case because...
end
 
% Version 2:
try
   data = doSomethingWith(data);
catch
   % do nothing in this specific case because...
end

In this case, Version 1 might fail to do the expected thing if you have a problem (bug or exception) in either someCondition() or doSomethingWith(). On the other hand, Version 2 will, in the worst case, keep data unchanged and then proceed with the rest of the downstream processing. For many (but certainly not all) use-cases this would be better than erroring-out on an exception, as in Version 1. Version 2 is also faster than Version 1 due to the avoided condition checks (some checks could take a noticeable time to execute).

Perhaps the question is a matter of expertise level: just as inexperienced drivers should be much more careful in their driving than experienced ones, so too should inexperienced programmers be more careful in their programming while experienced developers have more leeway.

]]>
Comment on String/char compatibility by Siyi Denghttps://undocumentedmatlab.com/blog/string-char-compatibility#comment-431292 Thu, 28 Jun 2018 22:21:27 +0000 https://undocumentedmatlab.com/?p=7710#comment-431292 It’s Easier To Ask Forgiveness Than To Get Permission.

]]>