Matlab Figure Dimensions Changing after Displaying

1 view (last 30 days)
I'm trying to draw a circle in the middle of some axes, as part of a UI. It should be simple, but I'm having an annoying issue I can't figure out. The full code (simplified, to isolate the problem) is at the bottom of this post.
For a split second, it appears perfectly (it's quick - you have to be focussed on the screen after you run the function to see it). Then the image 'shifts' upwards and to the right. If you use the data cursor, you can see that it still thinks the middle of the circle is the middle of the image.
I figured there must be something happening during me code to change this. After a lot of playing around, I found the change appears to happen after the function is done, which makes no sense to me. I set the figure to not be visible when initialised, then made it visible at the very end of the function (guiFigure.Visible = 'on'). Even when there is no code being generated after this, it still displays the correct image for a moment, then changes it. I added lines after this to display the positions of both the axes and the figure:
disp(app.displayAxes.Position);
disp(app.guiFigure.Position);
They appear perfectly correct. I then wrote "pause(3);" and then wrote the above two lines again. This time, it appears that the dimensions of the figure have changed from what I set them as. I then tried to manually set them back to what they should be, but without success.
Here is my code:
function testFunction()
width = 1920; % The width of both the figure and the axes
height = 1080;
guiFigure = figure('Visible', 'off', 'Position', [0, 0, width, height]);
displayAxes = axes('Units', 'pixels', 'Position', [0, 0, width, height]);
defaultImage = zeros(height, width, 3); % This is a test image to be displayed in the axes
defaultImage(:, :, 1) = 0.5; % It is simply a solid grey colour
defaultImage(:, :, 2) = 0.5;
defaultImage(:, :, 3) = 0.5;
imshow(defaultImage, 'Parent', displayAxes);
viscircles([width/2, height/2], 300);
guiFigure.Visible = 'on';
% The end of the function proper
% All lines after this point are for testing purposes
disp(displayAxes.Position);
disp(guiFigure.Position);
pause(3);
disp(displayAxes.Position);
disp(guiFigure.Position);
guiFigure.Position = [0, 0, width, height];
end
Edit: Note that I'm putting the axes in a figure because I'm ultimately making it part of larger UI.
I'm running Matlab R2016b. Any help would be appreciated!

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!