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

New to MATLAB?

Returning Plot handle From a function.

Asked by Tim Mottram

Tim Mottram

on 25 Sep 2012
Accepted Answer by Tim Mottram

Tim Mottram

Hi Guys,

I have a function called myFill which uses the following commands to plot two filled areas:

 f = fill(freqPoints,filledGood,goodColour,freqPoints,filledBad,badColour);
 set(f(1),'EdgeColor',goodEdge,'FaceAlpha',0.5,'EdgeAlpha',1)
 set(f(2),'EdgeColor',badEdge,'FaceAlpha',0.5,'EdgeAlpha',1) 

I want to be able to add a line at a later point in my code so I know I need the handle to the plot. But when I try:

 [ax,f] = fill(...)

I get the error "To many output arguments."

Can someone tell me how to return a handle to the plot, which can be used to up date it with a new line, please. Thanks in advance.

Kind regards,

Tim.

0 Comments

Tim Mottram

Tim Mottram

Products

No products are associated with this question.

2 Answers

Answer by Tim Mottram

Tim Mottram

on 25 Sep 2012
Edited by Tim Mottram

Tim Mottram

on 25 Sep 2012
Accepted answer
H = myFill
f = fill(freqPoints,filledGood,goodColour,freqPoints,filledBad,badColour);
set(f(1),'EdgeColor',goodEdge,'FaceAlpha',0.5,'EdgeAlpha',1)
set(f(2),'EdgeColor',badEdge,'FaceAlpha',0.5,'EdgeAlpha',1) 

THEN

H = gca
 end

Outside function:

 hold on
 H = plot(x,newLine)
 hold off

0 Comments

Tim Mottram

Tim Mottram

Answer by Wayne King

Wayne King

on 25 Sep 2012
Edited by Wayne King

Wayne King

on 25 Sep 2012

you don't use two output arguments, just

    h = fill()

If you want a handle to the current axes, you can just do

     ax = gca;

with the plot active.

0 Comments

Wayne King

Wayne King

Contact us