Code covered by the BSD License  

Highlights from
savehold: Run the 'hold on' command and save its state for possible restoration

5.0

5.0 | 1 rating Rate this file 2 Downloads (last 30 days) File Size: 1.73 KB File ID: #26574

savehold: Run the 'hold on' command and save its state for possible restoration

by Petr Pošík

 

03 Feb 2010

A small utility encapsulating the call to 'ishold', 'hold on' and a restortion of the hold state.

| Watch this File

File Information
Description

Assume we have axes inside a figure with some plots already there. We want to add some plots and then restore the state of hold (if it was 'on' before, we want it to stay 'on' after; if it was 'off' before, we want to set it back to 'off').

It can be done by the following commands:

>> % Commands plotting something and setting 'hold on' or 'hold off'
>> % Now, we want to add some plots
>> washold = ishold; % Get the 'state of hold' for the current axes
>> hold on; % Set the 'hold' property to 'on'
>> plot(something);
>> plot(something different);
>> if ~washold, hold off; end % Reset the state of hold if needed

With SAVEHOLD, the above code can be simplified a bit to:

>> % Commands plotting something and setting 'hold on' or 'hold off'
>> % Now, we want to add some plots
>> h = savehold();
>> plot(something);
>> plot(something different);
>> h.restore();

Acknowledgements
This submission has inspired the following:
Take & Restore hold
MATLAB release MATLAB 7 (R14)
Other requirements Uses function handles.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
03 Feb 2010 John D'Errico

I'll admit, this is a simple thing. Nothing dramatic here, with only a couple of lines of simple code. But it might make your own code just a wee bit simpler to write and to read later on. And simple, modular code is always good. If holds on plots are something you do often, then you may like this utility.

I like the help. An H1 line, etc. The 5 rating is a tip of my hat to the author.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
graphics Petr Pošík 03 Feb 2010 10:24:04
plot Petr Pošík 03 Feb 2010 10:24:04
plotting Petr Pošík 03 Feb 2010 10:24:04
hold Petr Pošík 03 Feb 2010 10:24:04
hold on Petr Pošík 03 Feb 2010 10:24:04
hold off Petr Pošík 03 Feb 2010 10:24:04
ishold Petr Pošík 03 Feb 2010 10:24:04

Contact us at files@mathworks.com