Matlab returns incorrect figure size when using figure with custom toolbar

21 visualizaciones (últimos 30 días)
Hello all,
I created my own GUI using guide which consists of two figures of the same height which I keep attached to each other. One of these figures I have equipped with a custom toolbar. I found that when saving the figure with custom toolbar and then reopening the resulting FIG file, the height has shrunk, in my case by 27 pixels. In fact, when requesting the position information for the figures, the value returned for the height is incorrect! It appears Matlab does not take into account the toolbar dimensions.
Is anyone familiar with this issue? I'm using R2017a.
  2 comentarios
Rik
Rik el 6 de En. de 2020
Which exact properties are you retrieving? And what is your exact goal with saving the GUI as a fig file?
It also sound like whatever you are trying to do is much too complicated for GUIDE to be an effective tool. Consider building your GUI from code instead. For an outline of your options, read this.
Sjouke Rinsma
Sjouke Rinsma el 17 de En. de 2020
Editada: Sjouke Rinsma el 17 de En. de 2020
Perhaps I was not completely clear due to wanting to be brief about the explanation. What I have actually done is to create two GUI's using guide; one figure containing an axis and another figure which opens the first and contains the tools to load and plot data on the axis in the first figure. These two figures I keep attached to each other by using a listener on the position. All functionality I have added directly in the code of the m-file generated by guide.
Now, as said I keep these figures (horizontally) attached to each other and both have the same height. When requesting the figure positions for both these figures, the height returned for the figure with the axis (with contains a custom toolbar, the other figure does not) is actually 27 pixels less, which led me to conclude Matlab did not consider the height of this custom toolbar in the figure position.
As it turns out this is actually the case, but it is not incorrect as I thought before. Apparently, a 'figure' does not include the toolbar, and thus does not consider it's size. I find this a bit shady since the MenuBar and normal ToolBar are members of the 'figure' object (also these are apparently not included in the figure position). As for the custom toolbar; it is not even a part of the figure, but (using "findall(groot)") an element by itself. The solution is to use the OuterPosition for connecting these figures.
Anyway, thanks for your contributions!

Iniciar sesión para comentar.

Respuestas (1)

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro el 6 de En. de 2020
I would support the idea of doing this through code. What you also do is once you have generated the GUI, grab the handles of the figure.
>> handleFig = gcf;
or if you are starting with a new figure
>> handleFig = figure();
Then you can check the dimensions of the figure:
>> handleFig.Position
ans =
440 378 560 420
And save those values in some way so that when you re-open you can re-size your figure. Please notice that those values are absolute, so they depend on your configuration, e.g. in my case
>> h0 = get(0);
>> h0.ScreenSize
ans =
Columns 1 through 3
1 1 1440
Column 4
900
Hope that helps

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by