place Figure handles in vektor

Hello im making a funtion were its possible to typ in a fnction and make a plot of it,
function plot_handles=skapaplot(varargin)
syms x X;
global plot_handles;
persistent n;
if isempty(n)
n = 1;
else
n = n + 1;
end
funk=input('function:','s');
figure;
ezplot(funk);
plot_hanldes(n)=gcf;
end
I want to keep track of how many figure and other information about the line in the plot, in the vector plot_handles. how can i do it in a easy way?

6 Kommentare

Daniel Shub
Daniel Shub am 22 Mai 2011
Other than a couple of typos and the fact that you are trying to return a global variable, what is your problem?
yngv
yngv am 22 Mai 2011
the varible plot_handles starts att the size 1 2, should'nt it be 1x1?
the main problem is to keep track of how many figures i got because i want to rerun the function n times
Daniel Shub
Daniel Shub am 22 Mai 2011
not on my computer.
yngv
yngv am 22 Mai 2011
i think the varible n is a problem in the function that makes plot_handles bigger then it should be, because it doesnt reset it self after ive stoped using the function
yngv
yngv am 23 Mai 2011
problem solved now, it works fine after clearing the memmory, but very annoying that it doesnt clear itselft between running the main file
Jan
Jan am 23 Mai 2011
@yngv: I do not think this is annoying, but a suboptimal design.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Jan
Jan am 23 Mai 2011

1 Stimme

A cleaned version of your function, which avoid using global variables:
function Reply = skapaplot(Command)
persistent plot_handles
if nargin > 0 && strcmpi(Command, 'gethandles')
Reply = plot_handles;
return;
end
syms x X;
funk = input('function:', 's');
FigH = figure;
plot_handles = cat(2, plot_handles, FigH);
ezplot(funk);
Now the function replies the list of handles, if it is called with the input 'gethandles'.

1 Kommentar

yngv
yngv am 23 Mai 2011
thanks, kind of got it work yesterday but with clearing the memmory between the runs, but to keep the count in the plot_handles is smarter becuase its always starts as an zero matrix in the main program :=)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 22 Mai 2011

Community Treasure Hunt

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

Start Hunting!

Translated by