I would like to create a figure, and once subplots have been created, I would like to apply properties to all of them simultaneously, without going through a for-loop. In fact, I would like to do all the following without having the need to go through a for-loop:
Is there a way to do this?
The most convenient approach is to create an array of axes handles, and then to set properties:
for i=1:4,
axesHandles(i) = subplot(2,2,i);
plot(...)
end
%# set background to black for all handles in the array
%# note that this needs no loop
set(axesHandles,'color','k')
If you don't have the axes handles collected, you need to collect the array of handles first. For this, you can use the children properties of the figure window (gcf
gets the handle of the currently active figure)
axesHandles = get(gcf,'children');
and if you have axes across several figures, you can use findall
to collect everything:
axesHandles = findall(0,'type','axes');
From then on, it's again a single call to set
, or to axis
, for example
set(axesHandles,'color','k','lineWidth',2)
axis(axesHandles,'tight')