Manage layout of docked figures - matlab

I'm writing a program who will generate a couple of figures and I want to dock them all together. I can, to dock them, use the command:
set(fig1,'WindowStyle','docked');
set(fig2,'WindowStyle','docked');
etc.
But I can't find how to manage the layout of the figures inside the container or even the container size from the code. Is there a way to do it?

You cannot set the Position property when figures are docked.
From Docking Figures in the Desktop:
If WindowStyle is set to docked,
MATLAB automatically sets DockControls to on.
You cannot set the DockControls property to off.
You cannot set the figure Position property.
As for laying out the figures, you could use subplot to display multiple plots in one figure, which you can dock.

There's no documented way to programmatically set the docking group of figures.
However, I believe #Yair Altman's setFigDockGroup, available from MATLAB Central File Exchange, enables you to do it (by manipulating undocumented properties of the figures and the MATLAB desktop).
Even if it doesn't quite do what you need, I would guess that by looking through that code you would find a way to do it (although you might need to be comfortable with a bit of Java).

There is an undocumented way to achieve this. You can get inspiration from FileExchange: http://www.mathworks.com/matlabcentral/fileexchange/46352-editor-session-manager.
This is saving the layout for the Editor Group.
One could adapt for a figure group.

Related

Save Matlab figure without plotting it and afterwards open it in VISIBLE state

I have the same question asked here: Save Matlab figure without plotting it?
But the problem with the solution given there is that I can't open the saved figures in visible state with doubleclick afterwards. Looks like the savefig command saves the visible state. Same with saveas.
h=figure;
set(h,'Visible','off');
savefig('TestExample.fig');
b=openfig('TestExample.fig');
With this command I can see the figure, but I simply want to doubleclick and see it:
set(b,'Visible','on');
The best solution for me is (thanks for links, How to edit property of figure saved in .fig file without displaying it):
figure('Visible','off')
set(gcf,'Visible','off','CreateFcn','set(gcf,''Visible'',''on'')')
savefig('Test.fig')
close
Figures don't pop up and I can open them visible with doubleclick only.
The documentationĀ seems to shed some light on the issue:
Create a surface plot and make the figure invisible. Then, save the
figure as a MATLAB figure file. Close the invisible figure.
surf(peaks)
set(gcf,'Visible','off')
savefig('MySavedPlot.fig')
close(gcf)
Open the saved figure and make it visible on the screen.
openfig('MySavedPlot.fig','visible')
...however, sadly it probably will not work when you use the double-clicking interface. The issue has been discussed also here, and would require changing the default behaviour of openfig. It is possible by editing the built-in function, but kind of dirty.
Another workaround solution is suggested in the comments further down by Jesse Hopkins:
Set the ResizeFcn on the figure to renable visibility. According to Matlab documentation, and in practice, ResizeFcn is called when figure is created:
set(h,'ResizeFcn','set(gcf,''visible'',''on'')');
The nice thing is, this workaround should work for setting on-load any property you might want to set on the figure handle being loaded.

How can I create a tab in MatLab GUI?

I am sorry for asking the same questions which has been asked before. But the thing is I am not in matlab for a long and especially during trying to build a GUI I am crossing some problems which looks like complicated when l compare which C#.
Now I am using Matlab 7.12.0(R2011a) and I want to know the possibility to add tab in my GUI to make it more clear.
I am appreciate for answers which could give me an idea to figure out.
Thanks.
You can create tabs using uipanels where you toggle the visibility to reproduce the tab like behaviou, there are a few utilisties on the Matlab FEX.
To do this you need to be happy with creating GUI's using code only (no guide).
If you do want an easy interactive way of creating a GUI with tabs then I have my own commercial GUI toolbox that creates very nice tabs.

Difference between position of elements of GUI before and after open it in GUIDE in MATLAB

I'm designing a GUI with GUIDE. When I open a window in GUIDE and after that run it, position of elements like panels,radio buttons and etc are difference with when I run MATLAB and directly run a GUI from .m file. It is a confusing problem because the real positions are that I'm running from .m file.
All elements of the window are nearly 1 cm to the right compared to when running it directly and I have a little vertical difference between these two. I should design a window and after that close MATLAB and run it directly to see the real positions! If I directly open it from .m file after using GUIDE, there isn't any difference with running from GUIDE and run from .m file. I have to restart MATLAB to see the difference.
What is your idea about this problem? How can I solve it?
Idea 1
This is more of a workaround rather than a solution:
What you could do, after positioning all elements in GUIDE, is to export the figure to an .m file (you don't actually need the .fig in order to have an interactive figure) using the menubar option File > Export ... in GUIDE.
This way you'll get an .m file with all the elements' positions hardcoded. If you change the position values from that file, there is absolutely no chance that they'll appear someplace else.
Idea 2
Try setting the Resize behavior of the GUI to Non-resizable. This is accessible from the GUIDE menu by Tools > GUI Options...

Unable to change GUI size in MATLAB's GUIDE interface

For some reason I am unable to resize the workspace size of a GUI figure using MATLAB's built in GUIDE editor. Every time I do so (by dragging the corner of the workspace), I get a warning in MATLAB's console stating:
Warning: Cannot set Position while WindowStyle is 'docked'
> In guidefunc>resizeFigure at 2693
In guidefunc at 116
I have tried setting the default window style to 'normal' (set(0,'DefaultFigureWindowStyle','normal')) to no avail.
I see no reports of this strange behaviour elsewhere online, and wonder if anyone else has experienced this?
Am using MATLAB R2012a. Any thoughts appreciated(!)
Improving upon Lucius' answer, I was able to resize the figure after using the following command on the workspace window.
set(gcf,'WindowStyle','normal')
This command helps sets the window style to normal and hence is resize-able.
I am using Matlab R2020b and the figure under question was selected (highlighted) before I ran this command.
Default-Window-Style and Window-Style are two different things. If you want to change the WindowStyle, you should use that property.
In addition take care for the handle of the figure!
%get handle:
myFigure= findobj('Tag','SomeUniqueTagHere') %make sure to get the right one
set(myFigure,'WindowStyle','normal')
I guess (but I'm not absolutely sure) default-properties will just be used during creation.
You can resize the workspace in GUI and therefore avoid the error message
Warning: Cannot set Position while WindowStyle is 'docked'
by changing the setting WindowStyle in the GUI. To the end you should:
Go to the GUI
Double click on the background, which makes appear the inspector panel.
Go to the property WindowStyle and change it from docked to normal.
After that you can resize your workspace normally.

Create tabs in a matlab GUI

How can I create tabs in matlab gui?
I did something like this a while ago...
I mean I created some menus at top of my GUI and then pressing each menu will set visible property of some controls on and the others get off
that way is useful for small GUIs but in beag GUIs it encounters problems and editing the GUI gets hard
I need someway to create seperate GUIs acting just like Mozilla tabs
Is there anyway to create that?
Tabs aren't officially supported yet, even though there exists the semi-documented function uitab. Note that in 2012a it warns you that the function will change.
However, there is a very nice submission on the File Exchange, the GUI layout toolbox that comes with tab functionality.
Matlab supports tabs from R2014b
See uitabgroup