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.
Related
I am currently working with Simulink and out of the sudden, I am unable to change the Model Configuration Parameters.
Whether I try to open the window via RightClick->Model Configuration Parameters or via Ctrl+E, in both cases, a blank white window opens.
This problem persists after a reboot and opening/closing MATLAB. Furthermore, it is the case for any model (whether old, new, untouched, example...) on my computer. Yesterday I searched for 45min for possible solutions but could not find any.
Is there some graphics cache or can you think of another way, how I could get the dialog back? A photo is attached:
Screenshot: Configuration Parameters window stays blank
Thanks a lot in advance!
This problem happens in Academic version on Simulink. I have not seen it in Original software.
A solution for your problem can be :
1) clear cache of Simulink by typeing the following command in command window :
rehash toolboxcache
2) reset menu and toolbar of Simulink by the following command :
sl_refresh_customizations
Then close MATLAB by exit command.
I have been working on an gui developed using the GUIDE in Matlab. The current gui, I mean the general figure window contains all types of sliders, buttons, editboxes, etc...
After awhile, I added a toolbar to my gui which included the Save tool. I have not changed any specifications regarding the save tool. I used the one already in GUIDE toolbar editor.
After clicking it, my gui program is stuck at that very instance I pressed the save tool and I cannot do anything else with it. It also opens in the same situation even after restarting the PC. I do not get any errors.
I would appreciate any help. How to restore functionality to my gui?
Unfortunately the "Save" tool's default is not "Save As" with a prompt it is just the normal "save" which immediately overwrites. The tool saved your current figure (or GUI). Meaning it overwrote the fig file of your GUI with the current state.
So when you pressed "save" uicontrol visibility, values, slider positions, edit box text etc. all was written into the FIG file. So the next time you launch it is all still in there.
To Fix it you will probably have to edit in GUIDE and try to clear / reset everything to your desired initial 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.
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...
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.