help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Running functions with same name located in different directories


From: Richardson, Anthony
Subject: RE: Running functions with same name located in different directories
Date: Tue, 25 May 2010 10:39:19 -0500


From: veryhappy 
> Subject: Running functions with same name located in different
directories
> 
> I have some functions that have the same name and have the same
> parameters
> for input and output but they produce a very different result (One
> produces
> a filter with Butterworth response in frequency and the other does the
> same
> but with Chebyshev). They're located in different directories and i
> want to
> freely choose
> wich one to use without changing to the directory it's located.
> Is there a way to do it??
> So far I'd tried with function handles but they doesn't work very
> well.I'd
> tried too to add them to the path but that won't let me decide wich
one
> to
> choose

You can use the "source" command to redefine the desired function:

> source("butterworth/filter.m");
> # Now filter function defined will produce butterworth result
> filter(5, 1000);
>
> source("chebyshev/filter.m");
> # Now filter function defined will produce chebyshev result
> filter(5, 1000);

You could define a dispatch function to source the appropriate file
and then call "filter".

However, I'd recommend giving the two files different names and then
defining a dispatch function that calls the appropriate function
depending on an argument:

> filter(5, 1000, "bw")      <- calls filter_bw function in filter_bw.m
file
> filter(5, 1000, "ch")      <- calls filter_ch function in filter_ch.m
file

Tony Richardson



reply via email to

[Prev in Thread] Current Thread [Next in Thread]