place Figure handles in vektor

7 views (last 30 days)
yngv
yngv on 22 May 2011
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
yngv
yngv on 23 May 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 on 23 May 2011
@yngv: I do not think this is annoying, but a suboptimal design.

Sign in to comment.

Accepted Answer

Jan
Jan on 23 May 2011
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
yngv
yngv on 23 May 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 :=)

Sign in to comment.

More Answers (0)

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!