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 Comments

Other than a couple of typos and the fact that you are trying to return a global variable, what is your problem?
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
not on my computer.
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
problem solved now, it works fine after clearing the memmory, but very annoying that it doesnt clear itselft between running the main file
@yngv: I do not think this is annoying, but a suboptimal design.

Sign in to comment.

 Accepted Answer

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 Comment

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 :=)

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Asked:

on 22 May 2011

Community Treasure Hunt

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

Start Hunting!