Why do I get the error "Identifier 'D' is not a function or a shared variable. To share 'D' with nested function, initialize it in the current scope"?

I got this matlab toolbox called WAFO (Wave Analysis for Fatigue and Oceanography) and when I try to use one of their function files (see attached file), I get the following error:
"Identifier 'D' is not a function or a shared variable. To share 'D' with nested function, initialize it in the current scope. For more information, see Sharing Variables Between Parent and Nested Functions."
I checked this document but I could not resolve the issue. I would highly appreciate if anyone could use this function file with the inputs stated in the comments in the file and help me solve this problem. (I know it's a fairly long file but the error is to do with only 1 variable).

4 Comments

In
[yy,p]= cssmooth(x,y,p,xx,LinExtrap,d2)
what did you pass in for all those variables? Maybe you need to pass in D also.
Thank you for responding @Image Analyst, I personally didn't code this up but I ran their example, which is this:
% Example:%
x = linspace(0,1).';
y = exp(x)+1e-1*randn(size(x));
pp = cssmooth(x,y,.9);
plot(x,y,x,cssmooth(x,y,.99,x,0,0.01),'g',x,ppval(pp,x),'k',x,exp(x),'r');
If you go to line 209, D is defined there, inside a nested function.
@Keith Adams Yeah, I basically edited line 141 and wrote this:
[u,D] = computeU();
It used to output only u. In addition to this, I edited a nested function (line 203) with the following line:
function [u,D] = computeU()
Hope this helps. Also if you are using WAFO like me, I cannot guarantee this is what the person who created this toolbox intended to do. But it seems to be working and I get their results (I think).

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

tng
on 27 Mar 2021

Commented:

tng
on 29 Mar 2021

Community Treasure Hunt

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

Start Hunting!