function call

조회 수: 7 (최근 30일)
Baba
Baba 2011년 11월 16일
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
Walter Roberson
Walter Roberson 2011년 11월 16일
Is pwd perhaps returning a relative directory rather than an absolute directory?

댓글을 달려면 로그인하십시오.

답변 (1개)

Honglei Chen
Honglei Chen 2011년 11월 16일
You can add it to your path.
doc addpath
  댓글 수: 4
Baba
Baba 2011년 11월 16일
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 2011년 11월 16일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by