Optional input parameters in function definition causes problems when function is used during another function
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Functions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!