Using uicontrol in a figure
Mostrar comentarios más antiguos
I have a script that I use to plot track data that has three subplots within a figure. I want to use uicontrol to create a toggle button that has a callback to the matlab function grid so that I can toggle the grid on and off. The problem is that I can only toggle the grid in the last subplot but it doesn't work for the first two. Here's most of my plotting script:
%%Set up axes
figure('numbertitle','off')
set(gcf,'Name',filename);
h1 = gcf;
axis off
%%X Plots
subplot(2,2,1)
ax = gca;
%x_axis = get(ax);
xlim([t(1) t(end)])
ylim([-10 30])
ylabel('x [m]')
grid on
hold on
%%Y Plots
subplot(2,2,3)
ay = gca;
%y_axis = get(ay);
h3 = plot([t(1) t(end)],[-half_lane -half_lane],'--',...
[t(1) t(end)],[half_lane half_lane],'--');
set(h3,'Color',[0.5 0 0])
ylabel('y [m]'), xlabel('time [sec]')
xlim([t(1) t(end)])
ylim([-10 10])
grid on
hold on
%%X-Y Plot
subplot(2,2,[2 4])
axy = gca; % get the axis information
xy_axis = get(axy);
car_y = [0 -5.182] + xy_axis.YLim(1);
load 'car.mat'; image([-0.9350 0.9350], car_y, car); clear car; % plot the car for reference
set(gca,'YDir','normal','XDir','reverse'), hold on
xlim([-10 10]);
ylim([-10 25]);
xlabel('y [m]'), ylabel('x [m]')
title(filename,'interpreter','none')
grid on
axis equal
arc_plot([-sensor(1).orientation(2) sensor(1).orientation(1)], (270-sensor(1).orientation(3)), C(1,:));
arc_plot([-sensor(2).orientation(2) sensor(2).orientation(1)], (90-sensor(2).orientation(3)), C(2,:));
arc_plot([-sensor(3).orientation(2) sensor(3).orientation(1)], (90-sensor(3).orientation(3)), C(3,:));
arc_plot([-sensor(4).orientation(2) sensor(4).orientation(1)], -(90+sensor(4).orientation(3)), C(4,:));
xy_axis = get(axy);
%%plot lane
h = plot([-half_lane -half_lane],xy_axis.YLim,'--',[half_lane half_lane],xy_axis.YLim,'--');
set(h,'Color',[0.5 0 0])
%%link axes and insert grid toggle
linkaxes([ax ay],'x');
uicontrol(h1,'Style', 'togglebutton', 'String', 'Grid',...
'Position', [20 20 50 20],...
'Callback', 'grid');
Respuesta aceptada
Más respuestas (1)
Paulo Silva
el 6 de Jun. de 2011
0 votos
The grid command like you have in the callback only applies to the current axes so you have to do it for all axes, use the grid command with the axes handles or do something like this:
set(findall(0,'type','axes'),'XGrid','on');set(findall(0,'type','axes'),'YGrid','on') %this turns on all grids on all axes objects.
2 comentarios
Walter Roberson
el 6 de Jun. de 2011
Abbreviating the above:
set(findall(0,'type','axes'),'XGrid','on','YGrid','on')
Paulo Silva
el 6 de Jun. de 2011
thanks Walter :)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!