How to use path in a script in which another script is loaded?

So have a script1.m in which another script is loaded such like this: cd(fileparts(which(mfilename))); run('myload.m');
script1.m and myload.m is in the same folder. But what if I want to call script1.m from an other folder? I have to call it for example like this: run('../../scripts/script1.m');
But in this case at line run('myload.m'); script1 will find myload.m?

답변 (1개)

Adam
Adam 2016년 5월 31일
편집: Adam 2016년 5월 31일

0 개 추천

Add your folders to your path and save it. You don't need to cd in code to change directories when calling a function.
There is a 'set path' button in the home ribbon in Matlab, or you can do it programmatically with addpath if you really want.

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

질문:

2016년 5월 31일

편집:

2016년 5월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by