Matlab GUI: how to add docked figure group? - matlab

I would like to be able to add a figure container to a matlab gui...
In core matlab, with a docked window style you can have a large number of plots stacked one behind the other, all within a figure container with a tabbed list along the side of the container that you can simply click to bring a particular figure to the front.
Is there a way to have this sort of figure container in a matlab gui?

Use Ben Tordoff's GUI Layout Toolbox. It contains functionality for tabbed panels and dockable/undockable panels that can contain figures, and many other capabilities that you'll find very useful if you are creating GUIs in MATLAB.
You will need to organize your GUI code slightly differently, but it's not hard to learn and there are great examples in the documentation.
It's not really possible to do what you're describing with just regular MATLAB: figures will just dock into the main MATLAB desktop, not into your GUI specifically. The best way (without GUI Layout Toolbox) would probably be to fake a row of tabs using buttons next to each other, with callbacks on the buttons that deleted/hid one plot and drew/revealed another. There is a function uitab that does tabs, but before R2014b it's undocumented, and it's a bit of a pain anyway. Better all round to use GUI Layout Toolbox.

If you're open to play around with undocumented features, this can be done using the java objects behind the matlab figures, e.g. using a little tool from the fileexchange.
This will create a new dock group, just like MATLAB's container for figures, editor etc.

Related

Drawing borders around a group of components in Matlab Appdesigner

I am using Matlab 2019b Appdesigner.
I have an app with many buttons, user input boxes etc and for making the navigation easier, I want to draw borders around a group of components which are under the same functionality. How can I do this?
Edit: Thanks to Rotem, I see that I can use the Panel Container for this. But is there a way to change the color or width of the border. I see only option to do it if it was created with GUIDE, but not Appdesigner.

GUI Layout Toolbox - Strange display with card panel object

Context
Using the GUI Layout toolbox I have created an interface which basically is divided in two parts:
A toolbar area where the user selects the way he want to see data
A preview area to display data upon selected mode in the toolbar
For the preview area I used a uietxras.CardPanel object to switch between the view modes.
Problem
After some investigations, I discovered that if I display things in 3D (or 2D) in one of the preview card using surf (or pcolor) then it alters the display in the second card. If I display data in 1D only using plot commands I have not issue!
The issue I have when using pcolor/surf in one of the preview card:
Titles and labels seem to overlay in Preview 1
Axis borders are not displayed correctly in preview 2
Legend borders (when displayed) are altered also
If I only use plot commands in both preview modes I have no issue at all and cards are switching nicely.
Test case
My real code is really long, I have thus reduced it to the minimum so you can reproduce the issue:
https://gist.github.com/CitizenInsane/54f3c1eba2293d0e5264#file-guilayoutbug-m
Simply run the code and check the checkbox "Do 3D plot in preview 1" to see the issue happening when switching between the two preview modes:
Notes
As far I know, I'm using latest version of the GUI Layout toolbox (1.17).
I'm using R2013b for Matlab
I came across this issue as well. I'm afraid I never quite worked out what the cause was exactly, and it didn't appear in a very consistent way. The issue seems to be that plots on non-selected cards are not hidden properly, and get overlaid just behind and around the edges of the plots on the selected card.
I would encourage you to raise the issue with the authors of GUI Layout Toolbox via the comments on the toolbox's page at MATLAB Central, as I do think it's a bug.
Nevertheless, the reason I never followed it up myself is that I found a fairly straightforward workaround, which may also work for you. Each time the selected card is changed, I ran a simple function that deleted all children of all cards, and then re-plotted whatever I wanted on the selected card. It seemed a bit annoying to have to do that, but it worked, and removed any of the display issues you've come across.
Ok got it, the issue has nothing to do with CardPanel themselves, it is linked to the renderer of the figure.
Trying simple code below:
figure(42);
subplot(1,2,1);
plot(rand(1,12));
subplot(1,2,2);
peaks;
shading flat;
If the figure's renderer is set to 'OpenGL' (the default) ==> there are some glitches:
If the figure's renderer is set to 'zbuffer' ==> there is no glitch:
Setting the renderer to 'zbuffer' fixes the problem.
NB: Maybe OpenGL rendering can be fixed by fine tuning graphic card acceleration settings, but I don't know ... I issued opengl software and opengl hardware commands in Matlab and software rendering is worst than hardware rendering on my machine.
EDIT: Side notes
Transparency effects are only available if the renderer is set to 'openGL'. It is thus not possible to visualize at the same time both 1D and transparent-3D data without glitches (at least with hg version 1 in R2013b).
HG2 has no issue:

how to setup a programmatically resizable UI in MATLAB

I'm trying to implement a resizable MATLAB UI. But I'm encountering a lot of problems.
In fact, the use of the normalized command is compulsory in order to have a window that automatically resize its content. However the 'normalization' of the uicontrol items it is not always the same. For instance the popupmenu is different from the text and edit. Moreover the FontSize has another behavior with respect to the previous ones.
Is there a simple tutorial out there in which all this stuff is explained?
I didn't find any.
If you're doing this, I would seriously recommend using Ben Tordoff's GUI Layout Toolbox, available from the MATLAB Central File Exchange. It gives you GUI resizing almost for free, and much else besides, such as movable panels and well-implemented tab controls. It comes with good documentation, including some simple tutorials and a decent worked-through example.
Ben is from MathWorks consulting group, and the toolbox is used widely by MathWorks when delivering consulting projects. Although it's not a 'supported' MathWorks product, it's very reliable, and it's freely available for you to include in your own projects.
Without this, it's a huge pain to implement resizing on a GUI of any complexity - to do it properly you can't just rely on the 'normalized' property, you need to implement the ResizeFcn callback on everything, and pretty much re-lay everything out each time there's a resize.

Displaying Signals in Simulink

I have been searching for a long time and have yet to find a tutorial/answer so I am posting the question here. How can I render a continuous signal within Simulink as a bar graph? The bar graph should be behaving similarly as the native default scope block within Simulink. I.e.: the graph changes in real-time while the signal is running. The same functionality (or close to it) as scope, but in a bar graph format. Any help or directions are appreciated.
There is a Floating Bar Plot in the Simulink Extras->Additional Sinks library.
However, it has very limited functionality.
The best way to do this is to write an (m-code) S-Function. Although not difficult, it's not going to be trivial to do properly. Within the S-Function you'll need to do things like
initialize a figure window and an axes on it, and open the figure if it is still open (from a previous simulation).
update the plot (efficiently, and most likely using low level functions, not the bar function itself)
check that the user hasn't closed the figure, and only plot data if it hasn't (or reopen the figure if it has been closed).
You will most likely also need to use some of the block callbacks to do the right thing if the block is deleted (e.g. delete the figure too, if it's still open), copied, etc.

Make MATLAB panels automatically rescale. (Not using GUIDE)

I have created a basic MATLAB UI (without using GUIDE). I basically have a bunch of panels for various things, (sliders, axes, text boxes, etc).
The one thing I would like to do though, it make it so that they scale properly, when I resize the figure. Right now, I painstakingly have to make a re-scale function for every button, panel, sub-panel, etc etc to make it rescale correctly.
Is there an easy way to simply automate the re-scaling here?
Thanks.
Use the GUI Layout Toolbox from the MATLAB File Exchange. I haven't personally used dynamic resizing functionality, but that's one benefit of using this package.
It functions much like using uicontrols, except you can't use the inspect tool on these objects.
EDIT: If you're looking only to do resizing when the figure itself is resized, set the Units property for all your uicontrols to normalized.
You could also use the builtin, but undocumented uigridcontainer and uiflowcontainer.
They have the benefit of e.g. allowing to set contraints, such that e.g. your pushbuttons don't get increased in size, when the full figure does. Check the link for some examples:
http://undocumentedmatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/