Comments for Undocumented Matlab https://undocumentedmatlab.com Charting Matlab's unsupported hidden underbelly Tue, 14 Aug 2018 01:04:40 +0000 hourly 1 https://wordpress.org/?v=4.4.1 Comment on Uitable sorting by Yair Altmanhttps://undocumentedmatlab.com/blog/uitable-sorting#comment-435471 Tue, 14 Aug 2018 01:04:40 +0000 http://undocumentedmatlab.com/?p=2391#comment-435471 @Dan – uifigures are based on HTML and JavaScript, they are basically nothing more than a webpage displayed within a browser window. In comparison, legacy figures are based on Java desktop windows. So any customization that works on the Java-based figures and relies on Java (including uitable customizations) will never work in uifigures, and you cannot get the Java handle of uifigure components because they’re not based on Java.

For details on uifigure customizations, refer to the list of posts that have the uifigure tag.

]]>
Comment on Uitable sorting by Danhttps://undocumentedmatlab.com/blog/uitable-sorting#comment-435454 Mon, 13 Aug 2018 21:46:16 +0000 http://undocumentedmatlab.com/?p=2391#comment-435454 Thank you so much. This works well for UITables embedded in a traditional figure but I’m having issues getting findjobj to work when the UITable is embedded in a UIFigure, it just returns an empty array. (I have an application build in App Designer.) Is there another way to get the Java handle to the UITable when it’s in a UIFigure?

Thanks,
Dan

]]>
Comment on Fixing a Java focus problem by Joe Burgelhttps://undocumentedmatlab.com/blog/fixing-a-java-focus-problem#comment-434988 Fri, 10 Aug 2018 14:34:02 +0000 http://undocumentedmatlab.com/?p=1933#comment-434988 Hi Yair, Once again, saving my life! Thanks so much for what you do for all these years.

]]>
Comment on Customizing axes part 5 – origin crossover and labels by Sarahhttps://undocumentedmatlab.com/blog/customizing-axes-part-5-origin-crossover-and-labels#comment-434854 Thu, 09 Aug 2018 16:54:26 +0000 http://undocumentedmatlab.com/?p=6564#comment-434854 Thank you!

]]>
Comment on Using linkaxes vs. linkprop by Yaroslavhttps://undocumentedmatlab.com/blog/using-linkaxes-vs-linkprop#comment-434793 Thu, 09 Aug 2018 07:52:10 +0000 http://undocumentedmatlab.com/?p=5928#comment-434793 @Mark, the zoom function calls resetplotview (undocumented). It, in turn, resets all modes (X/YLimMode) to auto. That is why the listeners do not trigger.

To solve the issue, link these properties too:

linkprop([a1 a2],{'XLimMode','YLimMode'}); % trigger linking on double click
]]>
Comment on Using linkaxes vs. linkprop by Mark D.https://undocumentedmatlab.com/blog/using-linkaxes-vs-linkprop#comment-434667 Wed, 08 Aug 2018 11:53:00 +0000 http://undocumentedmatlab.com/?p=5928#comment-434667 @Yaroslav your solution works great, but the double mouseclick (of zoom out or zoom in), which puts the plot in the default optimized axes, doesn’t work or behaves the same, instead of just linking by linkaxes. Do you know the solution for that too?

x = 1:5;
y = randn(1,5);
 
figure;
a1 = subplot(1,2,1);
p1 = plot(x,y);
 
a2 = subplot(1,2,2);
p2 = plot(y,x);
 
addlistener(a1,'XLim','PostSet',@(~,~)set(a2,'YLim',get(a1,'XLim'))); % link a1.XLim to a2.YLim
addlistener(a1,'YLim','PostSet',@(~,~)set(a2,'XLim',get(a1,'YLim'))); % link a1.YLim to a2.XLim
% and vice versa
addlistener(a2,'XLim','PostSet',@(~,~)set(a1,'YLim',get(a2,'XLim'))); % link a1.XLim to a2.YLim
addlistener(a2,'YLim','PostSet',@(~,~)set(a1,'XLim',get(a2,'YLim'))); % link a1.YLim to a2.XLim
 
%Use case, Zoom about 4 Times in and zoom out per doubleclick an you will see, that it then doesn't update the axes
]]>
Comment on Multi-threaded Mex by Peter Cookhttps://undocumentedmatlab.com/blog/multi-threaded-mex#comment-434511 Mon, 06 Aug 2018 20:48:38 +0000 https://undocumentedmatlab.com/?p=7771#comment-434511 Yair,

One multithreaded mex file I can’t say enough good things about is getmatvar which, in addition to being faster than MATLAB builtins (i.e. matfile objects), allows you to read part of a struct without loading an entire mat file!

Also worth checking out is mexthread if you have a compiler with std::thread

I’ve seen a couple mex files pop up which use the BOOST library as well, but I can’t think of one at this moment. Maybe another reader can link to an example.

]]>
Comment on MathWorks blogs facelift by Jan Afridihttps://undocumentedmatlab.com/blog/mathworks-blogs-facelift#comment-434337 Sun, 05 Aug 2018 09:12:39 +0000 http://undocumentedmatlab.com/?p=4573#comment-434337 Thanks for community referring. I wish this help to understand Matlab and resolve the issue that I am facing.

]]>
Comment on Scrollable GUI panels by David Sampsonhttps://undocumentedmatlab.com/blog/scrollable-gui-panels#comment-434170 Sat, 04 Aug 2018 08:24:36 +0000 https://undocumentedmatlab.com/?p=7824#comment-434170 See also uix.ScrollingPanel in GUI Layout Toolbox. This works for figures (not uifigures) from R2014b onwards.

]]>
Comment on Customizing uifigures part 3 by Yair Altmanhttps://undocumentedmatlab.com/blog/customizing-uifigures-part-3#comment-433520 Fri, 27 Jul 2018 16:24:24 +0000 https://undocumentedmatlab.com/?p=7169#comment-433520 @Royi – yes, but this is definitely not easy. Hopefully custom JS integration will be better in future Matlab versions. Perhaps I’ll post something similar to this sometime.

]]>
Comment on Sliders in Matlab GUI by Yair Altmanhttps://undocumentedmatlab.com/blog/sliders-in-matlab-gui#comment-433518 Fri, 27 Jul 2018 16:21:28 +0000 http://undocumentedmatlab.com/?p=5827#comment-433518 @Royi – I’m not familiar with any such control within Matlab, but you may possibly find such in one of the numerous online Java libraries (there were hundreds of thousands of Java libraries online, more than 10 times more than in the Matlab File Exchange). Then integrate the component in your Matlab GUI in much the same way.

]]>
Comment on Customizing uifigures part 3 by Royihttps://undocumentedmatlab.com/blog/customizing-uifigures-part-3#comment-433517 Fri, 27 Jul 2018 16:18:37 +0000 https://undocumentedmatlab.com/?p=7169#comment-433517 Hi,

Is there a way to import and use other JS UI libraries in MATLAB App Designer?

]]>
Comment on Sliders in Matlab GUI by Royihttps://undocumentedmatlab.com/blog/sliders-in-matlab-gui#comment-433514 Fri, 27 Jul 2018 15:55:09 +0000 http://undocumentedmatlab.com/?p=5827#comment-433514 Hi,

Is there a way to create triple slider?
Namely a slider with 3 knobs to set left, center and right value?

Thank You.

]]>
Comment on Customizing axes rulers by Yair Altmanhttps://undocumentedmatlab.com/blog/customizing-axes-rulers#comment-433365 Wed, 25 Jul 2018 11:06:05 +0000 http://undocumentedmatlab.com/?p=5116#comment-433365 @Vaishta – you have to read the Matlab documentation about how to create GUI callbacks and how to share data between GUI components/callbacks (https://www.mathworks.com/help/matlab/creating_guis/share-data-among-callbacks.html). In general, you need to store the axes handles in a location that is accessible to the callback function (for example, in the button’s UserData property). It looks like you’re using GUIDE to create your GUI, and in this case you could also access the axes handles via the handles structure.

I’m afraid that all this is pretty basic Matlab GUI stuff, which is not the subject of this blog – this blog specializes on advanced aspects, I leave the basics to the Matlab documentation and other forums/blogs. If you’re still having problems with this, you could either post a question on the Matlab Answers forum, or contact me offline for a private consulting session.

]]>
Comment on Customizing axes rulers by vaishtahttps://undocumentedmatlab.com/blog/customizing-axes-rulers#comment-433363 Wed, 25 Jul 2018 10:51:44 +0000 http://undocumentedmatlab.com/?p=5116#comment-433363 I have also tried the

set(ax1,'NextPlot','replaceall')
set(ax2,'NextPlot','replaceall')
set(ax3,'NextPlot','replaceall')

in the callback after the plot() function but its of no use … it still shows the old axes line, ticks and labels.
including the @axes1_DeleteFcn option in the callback but no use …

]]>
Comment on Customizing axes rulers by vaishtahttps://undocumentedmatlab.com/blog/customizing-axes-rulers#comment-433358 Wed, 25 Jul 2018 09:40:36 +0000 http://undocumentedmatlab.com/?p=5116#comment-433358 Thank you for information. Can you tell how to implement it in pushbutton callback ?
Because when I use following code

ax = ax1; ax = ax2; ax= ax3;
delete(ax1);delete(ax2);delete(ax3) 
...
...
ax1 = axes(...,'Position',[...])
plot(ax1,...)
ax2 = axes(...,'Position',[...])
plot(ax2,...)
ax3 = axes(...,'Position',[...])
plot(ax3,...)

at beginning of callback to delete axes handle
it throws error undefined function or variable ax1, ax2, … ax3

]]>
Comment on Customizing axes rulers by Yair Altmanhttps://undocumentedmatlab.com/blog/customizing-axes-rulers#comment-433357 Wed, 25 Jul 2018 09:14:37 +0000 http://undocumentedmatlab.com/?p=5116#comment-433357 @Vaishta – gca (=”get current axes”) only gets updated when you click or create an axes. If you want your button’s callback to refer to a specific axes, which may or may not be the currently-active axes, you should use not gca but the actual axes handle (the output of the axes function). Read the Matlab documentation for more information.

]]>
Comment on Customizing axes rulers by vaishtahttps://undocumentedmatlab.com/blog/customizing-axes-rulers#comment-433355 Wed, 25 Jul 2018 09:07:41 +0000 http://undocumentedmatlab.com/?p=5116#comment-433355 I have a GUI which has few pushbuttons using which I generate plots
1. In one of the pushbutton callback I use the ax = gca and set its position to make plots in at three different positions
2. In second pushbutton callback I use the ax = gca and set its position to make only one plot i.e at only one position.

However, when I press pushbutton next time, it still retains the old Axis values although it replaces data from plot. It appears very cluttered. This happens every time I use the pushbutton.
How can I clear the axes and set it fresh so that old axes and its values disappear ?

I have already tried these options below but no use … it still shows the old axes labels/tick labels etc.

ax = gca
delete(ax.Children)
ax.YRuler.Axle.LineStyle = 'none';
ax.XRuler.Axle.LineStyle = 'none';
ax.YRuler.HandleVisibility = 'off';
ax.XRuler.HandleVisibility = 'off';
]]>
Comment on Multi-threaded Mex by Yair Altmanhttps://undocumentedmatlab.com/blog/multi-threaded-mex#comment-433288 Tue, 24 Jul 2018 17:09:12 +0000 https://undocumentedmatlab.com/?p=7771#comment-433288 @Andy – In general I believe that it is better to use MEX’s mxMalloc/mxCalloc/mxRealloc/mxFree than their ANSI-C counterparts. This will ensure that all the MEX function’s memory is properly and automatically managed by Matlab’s memory manager, reducing the likelihood of segmentation violations and memory leaks. I admit that I did not follow my own advice in the code presented here. It doesn’t make much difference if you allocate and free the memory properly, but using the mx* variants is a bit safer in general.

Note that using mxFree to deallocate memory that was originally allocated using mxCreate*, or conversely using mxDestroyArray to deallocate memory that was originally allocated using mx*alloc, leads to a segmentation fault – mx*alloc should always and only be used with a corresponding mxFree, and similarly mxCreate* should always and only be used with a corresponding mxDestroyArray.

Another error occurs when trying to mxDestroyArray or mxFree within a C++ destructor, since at that point the memory manager has already freed the data.

]]>
Comment on Multi-threaded Mex by Andy Stampshttps://undocumentedmatlab.com/blog/multi-threaded-mex#comment-433279 Tue, 24 Jul 2018 14:47:15 +0000 https://undocumentedmatlab.com/?p=7771#comment-433279 Yair, Can you comment on what the distinction would be for using the ANSI C memory allocation routines (malloc/calloc/realloc/free) versus the MATLAB-specific variants (mxMalloc/mxCalloc/mxRealloc/mxFree)? The ANSI versions are used in your example above, and so I’m wondering if there was a specific rationale or if it comes down to personal preference.

]]>