GUI changing axes and using handles struct

12 views (last 30 days)
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
  3 Comments
Jan
Jan on 20 Oct 2014
Which part of the text is the question? Is the problem explained by this:
then any attempt to reveal (Visible) this signal on axes 2(for example) is not possible.
? If so, what does "not possible" mean? Do you get an error message or does the result differ from your expectations?
Is what due to the nature of the plot command?
I suggest to edit the original question and omit all sentences, which do not concern the problem. Neither "Alright, here goes" not the scaling of the axes matter. Your code would be readable, if you format it correctly.
Gary
Gary on 20 Oct 2014
yes, the problem is attempting to reveal the plot in a different axes does not occur....the plot is only visible in the axes it was originally created. no error code, just didn't follow my expectation.
this set of instructions creates the handles for each plot...initially setting the axes to axes1.
axes(handles.axes1)
for k=1:1:40;
hold on
handles.plotbuf00(k,:) = plot(num0(:,k),'r','visible','off');
end
hold off
The function checkBoxCallback determines which waveform to make visible. It will only make the plot visible in axes1, even though it is set to axes3
function checkBoxCallback(hObject,eventData,checkBoxId)
value = get(hObject,'Value');% indicates if the checkbox has been turned on=1 or turned off=0
%if turned on then make the waveform visible
%if turned off then make the waveform invisible...visbile =off
handles=guidata(gcbo);
axes(handles.axes3)
if value==1
set( handles.plotbuf00(checkBoxId),'visible','on')
else
set( handles.plotbuf00(checkBoxId),'visible','off')
end

Sign in to comment.

Accepted Answer

Adam
Adam on 20 Oct 2014
Edited: Adam on 20 Oct 2014
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).
  2 Comments
Gary
Gary on 20 Oct 2014
good info....I will see if I can use the Parent property to my advantage. As a backup I will use plot on demand....thanks for all the valuable suggestions.
Gary
Gary on 21 Oct 2014
I played around with the Parent property but couldn't manipulate using the handles structure reference....for example...handles.currentplot.Parent, error in Matlab, incorrect matrix reference...
I just added the lines of code which plotted visible OFF to all axes on the program initialization....
When buttondown on a axes was triggered, I updated a variable 'current axes' letting me know which axes was to be active....
I then used a simple IF statement.... IF current axes == 1 make waveforms visible in axes 1, else if .....
works great...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!