GUI with 2 uipanels, second axes not displaying

Hi,
I have a GUI with two uipanels. I use a "Next" button on uipanel 1 to hide uipanel 1 and make uipanel 2 visible. I use a "Back" button on uipanel 2 to hide uipanel 2 and make uipanel 1 visible.
On both uipanels, I display an image. While the image on uipanel 1 displays fine, I cannot seem to get the image on uipanel 2 to display. Could someone please identify how to get the image on uipanel 2 to display?
Please find the 3 GUI files attached. Thanks in advance for your time and effort in responding!

9 Comments

I do not see anything obvious at the moment. Have you confirmed that the callbacks are being invoked? Have you put a breakpoint into the callback and stepped through it?
Yes, I have stepped through it. I put a breakpoint in the GUI_inputScene_nextButton code at the end, and then made the following checks. To check that the axes of uipanel 2 is the current axes to be used by the imshow function, I used:
h = get(gcf,'CurrentAxes')
This returns 162.0150 which is the same value as handles.sensor_axes (the handle of the second axes).
To check that the second axes is made visible when the second uipanel is made visible, I checked that the axes is one of the children of the second uipanel, using:
get(handles.sensorPanel,'Children')
One of the values returned is 162.0150 once again, which is the same value as handles.sensor_axes (the handle of the second axes).
I thought perhaps it could be a problem with imshow, so I replaced it with
plot(1:100,1:100);
The same problem occurred. The plot showed on uipanel 1, but not on uipanel 2.
Just to make sure the imshow was plotting on the second axes (in GUI_inputScene_nextButton.m), I changed:
imshow(img);
to
imshow(img,'Parent',handles.sensor_axes);
However, this didn't make a difference.
About all I can think of the moment that might help is to replace your calls of the form
axes(THIS);
imshow(THAT);
with
h = imshow(THAT, 'Parent', THIS);
And then for debugging
get(get(h, 'Parent'), 'Parent')
and compare that against the handles of the uipanel. And just to cross-check,
findall(0, 'type', 'uipanel')
and make sure that two show up (that the uipanel did not get assigned the same id)
I like your cross-checking! Unfortunately, that doesn't seem to be the issue. Both uipanels retain their original handle IDs, and the imshow handle ID is a unique value that didn't exist previously.
I thought I should check to see if I could see any axes lines with the "Layer" and "Visible" properties. I replaced:
img = imread('cameraman.tif');
imshow(img,'Parent',handles.sensor_axes);
with
set(handles.sensor_axes,'Layer','Top','Visible','On');
plot(handles.sensor_axes,1:100,1:100);
The equivalent worked fine for the first axes (handles.inputScene_axes), but not for the problem axes (handles.sensor_axes).
I should also mention I am running R2013b (less likely to have a uipanel bug).
If you stop in the routine that creates the GUI, just after the callbacks are created, and at the command line you put an image into the sensor axes, then if you manually make the first panel invisible and the sensor panel visible, then does the image show up?
Thanks for the suggestion. I tried this with no difference. I finally found the answer, and have submitted it. I kept reducing the program complexity, and found that the second axes wasn't even displaying when I was plotting it on it's own uipanel with nothing else displaying! Please read my answer for the solution.
Walter Robertson, thanks again for all your troubleshooting suggestions. They were very much appreciated.

Sign in to comment.

 Accepted Answer

I finally found the problem. I didn't realise that the order in setting properties all at once (all on one line, or with ellipses (...)) is important. The order of setting properties is equivalent to setting the properties separately on a line of their own in the same order . I had assumed that if setting the 'Units' to be 'pixels' and setting the 'Position' on the same line, that MATLAB would interpret the 'Position' values to be in units of 'pixels'. I presume there are some very good reasons for MATLAB to interpret setting in this way (e.g. simplicity - Mathworks does not have to worry about how some settings might affect others when set simultaneously).
My specific error was the above issue for modifying the second axes settings. In declaring all non-default properties on one line using ellipses (...), I declared the 'Position' property with intended units of pixels before the 'Units' property of 'pixels'. The default 'Units' property is 'normalized', between 0 and 1. For my units in the hundreds, I think this meant the axes was plotted (in virtual space) a considerable distance outside the actual GUI area (only values 0 to 1 are observable), which is why the second uipanel was appearing blank.
This raises a second query - why didn't MATLAB warn me I was plotting an axes outside the visible area of the GUI? I have all the default errors and warnings enabled, and I would have thought this would be a useful warning. Is it worth me suggesting this to Mathworks?
So for the original code below:
% Exposed image axes
handles.sensor_axes = axes('Parent', handles.sensorPanel, ...
'Position', [300 50 900 500], ...
'Units', 'pixels', ...
'Visible','on');
I changed it to:
% Exposed image axes
handles.sensor_axes = axes('Parent', handles.sensorPanel, ...
'Units', 'pixels', ...
'Position', [300 50 900 500], ...
'Visible','on');

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!