function call

my function calculate needs to have a directory specified to work. and it won't work if I use "pwd". it only works if I specify the actual directory. how do I get it to work with pwd?
function x=calculate(chan,wd)
.....
end

1 Comment

Walter Roberson
Walter Roberson on 16 Nov 2011
Is pwd perhaps returning a relative directory rather than an absolute directory?

Sign in to comment.

Answers (1)

Honglei Chen
Honglei Chen on 16 Nov 2011
You can add it to your path.
doc addpath

4 Comments

Baba
Baba on 16 Nov 2011
why can't I just type in pwd instead of the full path in the function parameter?
Sven
Sven on 16 Nov 2011
Baba, type the following into MATLAB:
doc pwd
You see,"pwd" is just a function that returns the *current* directory. You don't want to use it in your function unless you *always want your function to search the current directory*.
Baba
Baba on 16 Nov 2011
well, I actually do want it in this case. and for some reason using pwd in the function parameter for directory does not work
Sven
Sven on 16 Nov 2011
So did you make a typo in your question when you wrote:
function x=calculate(chan,wd)
did you actually mean:
function x=calculate(chan,pwd)
?
If you meant the second line, then realise that you should *not* label variables in your function definition to be the same as built-in functions of MATLAB such as "pwd". Instead try something like:
function x = calculate(chan,myDir)
.....
end
And then you can *call* your function with the current directory as follows:
myOutput = calculate(1,pwd);
See the difference?

Sign in to comment.

Categories

Asked:

on 16 Nov 2011

Community Treasure Hunt

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

Start Hunting!