App Designer Axis Issue

50 次查看(过去 30 天)
Raees Mohammed
Raees Mohammed 2018-2-24
Hi, I'm creating an app in App Designer that allows a user to select different button configurations and then click a pushbutton to load a plot on an app.UIAxes. The problem is after you run the app a couple of times (the exact number I'm not sure), the properties of the app.UIAxes change such that it jumbles my plot together to the upper right corner of the axis. The way I fix this is by deleting the axis in the editor and replacing it with another. Then it runs and displays the plot on the axis as it should. This is what the axis looks like in the code that I cannot change for App Designer:
% Create UIAxes
app.UIAxes = uiaxes(app.LayerMappingUIFigure);
app.UIAxes.Position = [1 9 634 500];
When the axis displays the image in a jumbled, undesired way, the App Designer code I cannot change looks like this:
% Create UIAxes
app.UIAxes = uiaxes(app.LayerMappingUIFigure);
app.UIAxes.DataAspectRatio = [1 1 1];
app.UIAxes.PlotBoxAspectRatio = [1 1 1];
app.UIAxes.XLim = [0 1];
app.UIAxes.YLim = [0 1];
app.UIAxes.ZLim = [0 1];
app.UIAxes.CLim = [0 1];
app.UIAxes.GridColor = [0.15 0.15 0.15];
app.UIAxes.MinorGridColor = [0.1 0.1 0.1];
app.UIAxes.XColor = [0.15 0.15 0.15];
app.UIAxes.XTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
app.UIAxes.YColor = [0.15 0.15 0.15];
app.UIAxes.YTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
app.UIAxes.ZColor = [0.15 0.15 0.15];
app.UIAxes.ZTick = [0 0.5 1];
app.UIAxes.CameraPosition = [0.5 0.5 9.16025403784439];
app.UIAxes.CameraTarget = [0.5 0.5 0.5];
app.UIAxes.CameraUpVector = [0 1 0];
app.UIAxes.Position = [1 1 634 510];
I'm relatively new to App Designer, or app development in general. Can someone help me resolve this issue?
  3 个评论
Austin Herrema
Austin Herrema 2018-6-21
I would like to mention that I also experienced this. I have a fairly large app (approximately 10 uiaxes) and, seemingly randomly, many of the properties of all of the uiaxes were suddenly changed to 'manual'. I had not been modifying any of the properties in the App Designer or within the code. I ended up replacing all of the uiaxes rather than manually toggling everything back to 'auto'. I am using Matlab R2017b.
Dave
Dave 2019-6-21
I am using Matlab 2019a with Windows 10, using appdesigner for the first time. Similar to Austin, I have eight uiaxes in a grid. I keep source controlled versions of my code. Up to a certain point in development, the resize behavior of the grid of axes was as expected - the axes expanded accordingly when the main window was made bigger. After that point, the axes failed to change in size, leaving large unused grey gaps between the axes. I copied both versions of code out to another editor and performed a diff. I found in the newer version only that for each axes, a line similar to the below appeared in the "uneditable" code area:
app.UIAxes3.PlotBoxAspectRatio = [1 1.26190476190476 1];
I do not know what caused this code to be injected - I did not change properties manually in the appdesigner window, for instance. I suspected this was related to my resize problem because I know setting values explicitly can force the mode to manual. I confirmed this by setting the PlotBoxAspectRatioMode to 'auto' in my startupFcn, and seeing the behavior be correct again.
Coincidentally or not, other things occurred around the same time and may be relevant (or not).
(1) A couple of my code versions before this problem showed up, I added code to save the position of each element in the UI upon exit, and set the positions to their saved values upon startup: this to avoid having to perform the same resize operation manually every time I started the code. This involved setting only Position elements programmatically. I did not set any plot box properties. This worked perfectly for several days, then I started getting the undesired behavior listed above.
(2) At around the same time, my code in appdesigner reached about 1000 lines.
(3) The design view in appdesigner stopped showing me the uiaxes in my grid: the entire page in the tab that contains the grid is blank grey. I can still click where the axes are and see the selection box, so I know they are still there.
(4) It became impossible to copy and paste code in the code view. It can take many seconds for a paste to show up, if it shows up at all. This is not a "performance" issue, in that it didn't get slower and slower over time. It acts like a file-corruption issue, or a bug. I went from a smoothly working development environment to completely broken without a noticeable transition. It makes no difference if I turn off the "Enable app coding alerts" feature.
Both (3) and (4) were resolved by deleting and recreating my prefdir folder ( C:\Users\Name\AppData\Roaming\MathWorks\MATLAB\R2019a ).
Now pasting operations are merely slow, taking a second or so sometimes.
The point of all this being: maybe two or more of these things are related: the changing of properties to "manual", the corruption of files in the prefdir folder, and whatever underlies the 1000-lines-is-too-many issue.

请先登录,再进行评论。

回答(3 个)

Benjamin Kraus
Benjamin Kraus 2018-3-5
Based on the block of code that you say you cannot modify, it looks like App Designer thinks you have manually specified all those values. Once you have manually told App Designer to use a specific value for a property, App Designer will stop automatically calculating the value for you.
In this case, it looks like XLim and YLim (and many other properties) have been manually specified to be [0 1], which means that even if you plot data spanning from 10-100, MATLAB will try to honor your request to keep the limits at [0 1], and you won't see any of your data.
This could happen if you were browsing through the list of properties and click on each one individually, and App Designer (perhaps by mistake) interpreted that as as an intent to set a value. When you set a value, the corresponding mode value toggles to from 'auto' to 'manual'. To fix it, you can toggle the mode back to to 'auto'.
For example, looking at the list, App Designer thinks that you have manually set the values for XLim, YLim and ZLim. To tell App Designer to automatically calculate those values, you need to make sure that XLimMode, YLimMode, and ZLimMode are all set to 'auto'. You can do that for the Mode property corresponding to each of the properties in the list above.
Alternatively, you can delete the UIAxes and create a new one with new default settings. You can save yourself a little time by copying the Position before you delete the old UIAxes, create a new UIAxes, then paste the old value of Position to put your new UIAxes back into the same location as the old one.
Finally, it is worth pointing out a difference between how UIAxes and Axes behave when plotting:
  • Regular Axes will automatically reset all the properties (including XLim, YLim, etc.) when you call commands like plot.
  • UIAxes will typically not automatically reset any properties when you call plot. This means that any properties you have manually specified when designing your app will be preserved after a call to plot.
This difference in behavior is based around the value of the NextPlot property. On regular Axes the default value of NextPlot is 'replace'. On UIAxes the default value is 'replacechildren'.
You can read about the NextPlot property on the documentation page for the newplot command. Commands like plot call newplot internally.
If you want UIAxes to behave more like regular Axes, you can manually set the NextPlot property to 'replace' before you plot:
app.UIAxes.NextPlot = 'replace';
plot(app.UIAxes, 1:10)
or you can manually reset the axes using the cla command:
cla(app.UIAxes,'reset')
plot(app.UIAxes, 1:10)
  1 个评论
Sami Kanderian
Sami Kanderian 2018-11-11
编辑:Sami Kanderian 2018-11-11
I have the same problem and am using R2017b. I fixed it multiple times: I removed the axis and put a new one, but it happened repeatedly. It's so frustrating much so that I gave up on App designer and am switching to Java. Sure it takes longer to code algorithms in Java, but at least the UI behaves predictably and does not change unless I tell it to.

请先登录,再进行评论。


Raghu S
Raghu S 2018-7-26
This command solved my same issue. Just place this code in StartFCn cla(app.UIAxes,'reset')

Raghavendran Vagarappan Ulaganathan
Initially, the required data was not visible in my app.UIAxes.
I did the following steps:
1. app.UIAxes = uiaxes(app.LayerMappingUIFigure); % Blank axes appeared in my GUI
2. app.UIAxes.Position = [1 9 634 500]; % To move to the required position in the GUI
3. app.xdata, app,ydata % app.UIAxes x-axis and y-axis scaling
4. app.UIAxes.XLim app.UIAxes.XLabel.String app.UIAxes.YLim app.UIAxes.YLabel.String
5. plot(app.UIAxes,app.xdata,app.ydata) % to plot the required _data

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by