I'm curious why you are calling figure(1)?
I can think of three reasons you may be calling figure(1):
- You want to put the figure with the ID 1 on top of all other windows.
- You want to make the figure with the ID 1 the "current figure".
- You want to get a handle to the figure with the ID 1.
A fundamental difference between App Designer (and uifigure) vs. a regular figure is the HandleVisibility and the IntegerHandle.
Within App Designer (and when you create a figure using the uifigure command):
- The default HandleVisibility is 'off'. This means that your figure will never be the "Current Figure".
- The default IntegerHandle is 'off'. This means that your figures will not get integer numbers (such as "1") assigned to them.
This means that none of those three bullets above are going to work in an App Designer app, unless you reenable HandleVisibility and IntegrHandle. However, that is not recommended.
Consider this code:
In the code above, all but the first line of code relied on the "Current Figure" and/or the "Current Axes". This code pattern is discouraged in App Designer.
If you were to rewrite this code in App Designer, you would write it like this:
With this new code pattern, you are explicitly specifying the parent (or target) for every command, so you are no longer counting on the Current Figure or the Current Axes. This makes reason 2 above unnecessary.
Also, with this new code pattern, you are using a variable (f) to refer to your figure. This is a replacement for using an integer (such as 1). Using an integer to refer to figures is an outdated and discouraged code pattern. In R2014b we introduced graphics objects to represent figures, and this is the preferred method. This makes reason 3 above unnecessary.
If your reason for calling figure(1) is to put the figure on top of all other windows, then you want to use f instead:
You can get f by using a property on your app, or by storing the output from the figure (or uifigure) command.
However, while leveraging integer handles and the current figure/axes is discouraged in App Designer, it is still possible to do. What you need to do is set both HandleVisibility and IntegerHandle to 'on' within your App. Note, however, that your figure is not guaranteed to be assigned the integer 1, it will pick the next available unused integer.
This may allow you to contiue you using your script in App Designer, with only minor modifications, but it should be viewed as a temporary workaround until you have a chance to update the script to use the recommended pattern of storing and passing around graphics objects, and stop using integers to refer to figures.