Home > Archive > Matlab > August 2007 > Wrapping functions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Wrapping functions
|
|
|
| I want to wrap an existing function, for instance, to cause
all new dialogs that are opened to be blue (even if created
by anoter. I can do this by placing a function like the
following in the 'nd' (new dialog) directory:
function H = dialog(varargin)
found = 0;
for i = 1:2:length(varargin),
if strcmp(varargin{i}, 'Color'),
varargin{i+1} = [0.7 0.7 0.9];
found = 1;
end
end
if ~ found,
varargin{end+1} = 'Color';
varargin{end+1} = [0.7 0.7 0.9];
end
oldpath = path;
rmpath nd
H = dialog(varargin{:});
path(oldpath)
However, this doesn't work when compiled. Likewise, a
solution where I store off the function handle to the
original dialog() and then change the path also fails when
compiled.
How can I replace/wrap an existing function in such a way
that the wrapping will work even after compilation?
| |
|
| Sorry, meant to say "...even when created by another built
in function ,such as questdlg()"
Ray
| |
|
| On Aug 30, 12:56 pm, "Ray " <tho...@mit.edu> wrote:
> Sorry, meant to say "...even when created by another built
> in function ,such as questdlg()"
>
> Ray
On Aug 30, 12:56 pm, "Ray " <tho...@mit.edu> wrote:
> Sorry, meant to say "...even when created by another built
> in function ,such as questdlg()"
>
> Ray
Ray,
I haven't tried it, but here are my thoughts. Probably the simplest
way to do this is to create a new version of the dialog function, and
include an evaluation in the calling function to determine if an
override flag has been set. Something like:
function H=dialog(varargin)
if ~isempty(dbstack) % make sure we were called from someplace
if evalin('caller','exist('MakeAllBlue','va
r')) % Does the flag exist
flagcheck=evalin('caller','MakeAllBlue==
1'); % is the MakeAllBlue
variable true
H=dialog_original...(fill in your code here);
return
end
end
H=dialog_original(varargin{:}); %if the flag doesn't exist, isn't set
etc. Do normal behavior
This example assumes you took the original dialog function and renamed
it dialog_original (note that the orignal is a p-file, so that's what
you need to rename).
HTH,
Dan
|
|
|
|
|