views:

183

answers:

2

I am writing two small psychoacoustic testing applications in MATLAB. The first one works without problems but the second one doesn't, and I just can't figure out why.

Here is the problem: the axes object is created, but it is empty.

failed_axis

Here is the code that creates this figure and axes:

hFig = figure('dockcontrols','off','menubar','none', ...
              'name','choose the better sounding file', ...
   'numbertitle','off','position',[0,0,700,500], ...
   'resize','off','toolbar','none','units','normalized', ...
   'color',[.8,.8,.8]);
progress_idc = axes('position',[.1,.8,.8,.05],'box','on','parent',hFig,...
         'xlim',[-.03,1.03],'xtickmode','manual','xtick',[], ...
         'xticklabelmode','manual','xticklabel',[], ...
         'ylim',[-1,1],'ytickmode','manual','ytick',[], ...
         'yticklabelmode','manual','yticklabel',[], ...
         'nextplot','add');

And here is the code that plots in this axes (the function is called regularly by a timer):

function replot(varargin) % this is a nested function
    cla;

    % plot start_indicator
    plot([x_start,x_start],[-.7,.7],'k','linewidth',2);
    fill([x_start,x_start-.02,x_start-.02],[0,-.7,.7],[0,0,0]);

    % plot stop_indicator
    plot([x_stop,x_stop],[-.7,.7],'k','linewidth',2);
    fill([x_stop,x_stop+.02,x_stop+.02],[0,-.7,.7],[0,0,0]);

    % plot play_position
    plot([x_play,x_play],[-1,1],'r');

    drawnow;
end

This is what it looks like if it works:

proper_axis

Do you have any idea what is going wrong here?

+2  A: 

I ran the code you included above and got the correct output.

If I had to take a wild guess as to what the problem is, I'd guess that you may be creating other axes in your application that you are not listing above, or that you may have other axes not related to the application open at the time the application is running. When you plot your objects in the function replot, you are by default plotting them to the currently active axes. If you have multiple axes open, the plotting may therefore be going on in the wrong set of axes.

One suggestion I would make is to explicitly specify what the parent axes object should be in your calls to PLOT and FILL. If you add the arguments ...,'Parent',progress_idc); to your plotting calls, it will ensure that the correct axes is always used. I make a habit of always specifying the parent axes object instead of assuming that the currently active axes will always be the one I need it to be.

gnovice
+1  A: 

I finally found the (dumb) answer. The title accidentally had the same position as the plot axis. Due to some rendering-details of Matlab, it obscures the whole axis except for the rightmost and bottommost line of pixels, which makes the axis look "empty".

Oh, what a dumb error.

BastiBechtold
Yes, most errors seem to be dumb in hindsight. ;) From the image you posted, I didn't think the title text box extended that far down. Nevertheless, I still suggest using the advice I gave above and explicitly tell your plot commands where they should go.
gnovice
yes, that's good advice! It is certainly better to have the program explicitly do the right thing instead of relying on implicit assumptions (or chance!).
BastiBechtold

related questions