Function not running except from the source directory

조회 수: 3 (최근 30일)
Irina
Irina 2015년 3월 6일
댓글: Image Analyst 2015년 3월 6일
I saved my code in a directory which has been added to the pathdef.m file. But function call is not working from any other directory. I have to cd to the file source directory to run the code, but the code itself is running fine. What am I doing wrong?
Thank you!

답변 (2개)

Star Strider
Star Strider 2015년 3월 6일
I can’t tell from here, but if you saved your code to your user path (on Windows machines, C:\Users\USERNAME\Documents\MATLAB\), and used the addpath function if you saved it to a new subdirectory in that directory, you should be able to run it without problems.

Image Analyst
Image Analyst 2015년 3월 6일
If you type
>> path
on the command line, do you see the folder with your source code listed there? If you do, it should run no matter what your "current folder" currently is because it will be on your search path.
  댓글 수: 2
Irina
Irina 2015년 3월 6일
yes, the directory where code resides is listed in the path. but when i run it from c:\, it gives me the error. when i switch to the directory, it runs without a problem.
>> path
MATLABPATH
U:\CountryCharts
Image Analyst
Image Analyst 2015년 3월 6일
What do you mean "when you run it from c:\"? Is this a compiled program (standalone executable) or are you running an m-file source code from within the MATLAB development environment?

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

카테고리

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