MATLAB: GUI changing axes and using handles struct

gui handle struct

Alright, here goes….
my gui has multiple axes for plotting, I've setup 4 axes, axes1,….axes4
I have 40 analog signals with different Y axis limits, some signals are 0-1.0 others are 0-3600 plotting these on the same axes is not useful as the axes will be auto-scaled and the signal with the 0-1.0 limits will appear as a flat line losing its visual information.
I can play around with the y axis scaling, but decided to use multiple axes and the user will select a axes and plot what they need with the detail they need….
The analog signals are initially plotted with Visible OFF and the handles are saved for each plot. When the user selects a analog signal to display (from checkbox), I just turn the Visble to ON…..this works…great.
this set of code, sets the current axes to axes1, points to each column of data 1 to 40, while pointing at the column set the handle of the plot while visible OFF….works great…
axes(handles.axes1)
for k=1:1:40; hold on handles.plotbuf00(k,:) = plot(num0(:,k),'r','visible','off');
end hold off
guidata(hObject,handles);
Except the handle is always referenced to the axes of the initial plot command. That is, If I set the axes to axes 1, plot, visible OFF, …. then any attempt to reveal (Visible) this signal on axes 2(for example) is not possible.
when I need to reveal the selected waveform….I use the code…. function checkBoxCallback(hObject,eventData,checkBoxId)
value = get(hObject,'Value')
handles=guidata(gcbo);
if value==1
set( handles.plotbuf00(checkBoxId),'visible','on')
else
set( handles.plotbuf00(checkBoxId),'visible','off')
end
Is this due to the nature of the plot command? is the axes where the signal is plotted stored in its handle, if so, can it be manipulated.
If needed, I can work around this by initially plotting , visible OFF the signals on all 4 axes, and saving its handle on each axes
just throwing this out there to see if any slick option with Matlab is available…..
thanks gary

Best Answer

Unless I am missing something obvious, the behaviour you get is because of what I said above in the comment. When you plot the graphs you plot them on axes 1 therefore that is their parent axes, irrespective of which axes you bring into focus later on before changing the 'Visible' property of the lines.
If you want the same graphs to be plotted on 4 different axes and made invisible on each you would have to plot them initially on all four axes or re-parent them all when you wish to have them on a different axes, but that seems more trouble than simply plotting them again on the fly.
'Parent'
is the property of the line handle object that tells you the axes they are plotted in, by the way and one of the properties of that resulting axes handle object is 'Tag' which allows you to distinguish your axes, assuming you gave then tags.
As an example of re-parenting:
figure; hAxes1 = gca;
hLine = plot( 1:10, rand(1,10) );
figure; hAxes2 = gca;
hLine.Parent = hAxes2;
will plot a line on hAxes1 in the first figure and then move it to hAxes2 in the second figure.
As an aside, I tend to favour putting the axes as an argument to the plot command rather than relying on the vagueries of whichever happens to be the current axes, even after calling the axes command which is the way I used to do it (calling axes changes focus to the axes in question as well as making it the next one to plot on and I don't like that happening by default).