How do I set "hold all" for an array of axes handles?

3 views (last 30 days)
Tobin Fricke
Tobin Fricke on 14 Jun 2011
Suppose I have a vector of axes handles, for instance:
ax = subplot(2,1,1);
% ...
ax(2) = subplot(2,1,2);
% ...
I would like to set "hold all" for all of them, something like:
for ii=1:length(ax),
hold(ax(ii), 'all');
end
It would be nicer to simply be able to do:
hold(ax, 'all');
where ax is a vector of axes handles. But this is specifically disallowed. In hold.m there is even the comment, "must not be a vector of handles" -- why is this?
I'm not sure whether this is a question or a feature request. (-:

Answers (2)

Jan
Jan on 14 Jun 2011
If you look inside the source of HOLD, you see, that it is a wrapper for the command:
set(ax, 'NextPlot', 'add')
But exactly this command can be called als if ax is a vector.
HOLD('all') sets the NextPlot property of the figure also. This can be done manually also:
set(FigHandle, 'NextPlot', 'add');
  3 Comments
Walter Roberson
Walter Roberson on 15 Jun 2011
The documented behavior of hold all is,
===
hold all holds the plot and the current line color and line style so that subsequent plotting commands do not reset the ColorOrder and ColorOrder property values to the beginning of the list. Plotting commands continue cycling through the predefined colors and linestyles from where the last plot stopped in the list.
===
The major use of the color order would be in plot(), which is a built-in and so not searchable for particular text strings.

Sign in to comment.


Walter Roberson
Walter Roberson on 14 Jun 2011
The code simply isn't designed to loop around to process a vector of axes.
You can define:
holds = @(ax,varargin) arrayfun(@(oneax) hold(oneax,varargin{:}), ax);
and then holds(ax, 'all') would do the task.

Products

Community Treasure Hunt

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

Start Hunting!