Spacey
Spacey

Reputation: 3011

Want to make a line, using a handle to a figure in MATLAB

I have a problem, where I already have a handle to a figure created, and I want to somehow now draw a line, given that handle. For example, I have:

f1 = figure(1);
a1 = gca;

For commands like plot and surf, I can pass the axes and/or figure handles to tell it to plot to that particular figure. However, how do you do this with the line command? There does not seem to be a way as far as I know... thank you.

Upvotes: 1

Views: 135

Answers (2)

Shai
Shai

Reputation: 114866

Have you tried the `Parent' property?

line( x, y, 'Parent', a1 ); 

see line properties for more info.

Upvotes: 2

horchler
horchler

Reputation: 18484

The line function, like patch is a low level function. The plot command are built on top of these. However you can do this:

f1 = figure(1);
a1 = gca;
line([0 1],[0 1],'Parent',a1); % Parent has to be an axis handle

You can find more line options here: line properties or type doc Line_Props in the Matlab command window.

Upvotes: 4

Related Questions