MATLAB: GUI with 2 uipanels, second axes not displaying

guimultiple axesuipanel

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!

Best 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');
Related Question