Optional input parameters in function definition causes problems when function is used during another function
Show older comments
Dear all,
I have a function "density(d, r, k, dv, deltav)" where dv and deltav are optional inputs. To verify them i worked with:
if ~exist('dv','var')
do something
end
if exist('dv','var')
if ~exist('deltav','var')
do something else
end
end
in the definition of the function density. So I can call density(d,r,k) or density(d,r,k,dv) and it works. Now I have another function f2
function[a] = f2(other Inputs, d, r, dv, deltav)
...
for i = 1:n
k(i) = ...;
b = density(d, r, k(i), dv, deltav); %b is a Matrix %is in line 23 where the error occurs
a(i,:) = mean(b);
end
end
If I try now to call f2(other Inputs, d, r, dv) without deltav or even f2(other Inputs, d, r)
it gives me: Error using f2 (line 23) Not enough input arguments.
dv and deltav in f2 are only used in this specific line where density is called. So why do the "if exist" in density not work anymore? How can I solve this problem? Many thanks in advance
Accepted Answer
More Answers (0)
Categories
Find more on Functions 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!