Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
modify behavior of plot function

Subject: modify behavior of plot function

From: John

Date: 22 Apr, 2010 10:19:32

Message: 1 of 5

Hello,

I would like to have one of my matlab scripts automatically called when
another script calls the plot function.

What is the easiest way to obtain that?

Is it possible to create a listener which will listen for "plot events" and
upon detection of such an event call a function defined by me?

Thanks!

Subject: modify behavior of plot function

From: Sean

Date: 22 Apr, 2010 11:31:22

Message: 2 of 5

"John" <John@yabadabadooo.com> wrote in message <4bd022d5$0$274$14726298@news.sunsite.dk>...
> Hello,
>
> I would like to have one of my matlab scripts automatically called when
> another script calls the plot function.
>
> What is the easiest way to obtain that?
>
> Is it possible to create a listener which will listen for "plot events" and
> upon detection of such an event call a function defined by me?

You could write a new function 'my_plot()' which calls plot directly and then calls you other script.

function my_plot(varargin)
    plot(varargin)
    my_script();
end

Subject: modify behavior of plot function

From: John

Date: 22 Apr, 2010 12:37:12

Message: 3 of 5


> You could write a new function 'my_plot()' which calls plot directly and
> then calls you other script.
>

Yes, I thought about that, but it's not optimal in terms of code
maintenance. I believe it is possible to make an
overload for the plot function? (just dont know how) Or add a listener which
will listen for a "plot event" and then call a function
defined by me once the plot function has completed??

Subject: modify behavior of plot function

From: Steven Lord

Date: 22 Apr, 2010 13:38:20

Message: 4 of 5


"John" <John@yabadabadooo.com> wrote in message
news:4bd022d5$0$274$14726298@news.sunsite.dk...
> Hello,
>
> I would like to have one of my matlab scripts automatically called when
> another script calls the plot function.

_Instead of_ or _in addition to_ the PLOT function?

> What is the easiest way to obtain that?

The easiest way would be to define your own myplot function and call that
instead of PLOT, as Sean suggested. If that's not an option, my next
attempt would be to create your own subfunction or private function named
plot -- then the "definition" of PLOT would only change for the functions in
the function file containing that subfunction or the functions in the parent
directory of the private directory containing your private plot function
rather than for all MATLAB functions.

Just out of curiosity, why are you trying to intercept PLOT calls? What are
you trying to have your other script do when PLOT is called? Perhaps
there's a way to do what you want directly (like if you want to change a
property of the figure or axes, you could change the default property value
and so have the figure/axes be created using the new default property
value.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: modify behavior of plot function

From: John

Date: 22 Apr, 2010 19:42:56

Message: 5 of 5

> Just out of curiosity, why are you trying to intercept PLOT calls? What
> are you trying to have your other script do when PLOT is called? Perhaps
> there's a way to do what you want directly (like if you want to change a
> property of the figure or axes, you could change the default property
> value and so have the figure/axes be created using the new default
> property value.)
>


I would like to add something to the functionality of plot() such that
whenever plot() is called
then the resulting figure will automatically be saved to a jpg-file. I have
a bunch of
scripts which I am not allowed to change. These scripts have several calls
to the plot function. So I
need to modify the behavior of the plot function (add some functionality to
it).

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us