1

I'm running a script in folder A, which needs to call functions and .exe's inside folder B. I used addpath(C:\...\B) in the script, but only the functions (.m) in B are reached successfully, not the executable files (.exe). However, both .m and .exe are accessible if I run the script under folder B and select "add to path". Why doesn't addpath work?

horchler
  • 18,384
  • 4
  • 37
  • 73
Z Cao
  • 583
  • 1
  • 5
  • 19

2 Answers2

2

Addpath modifies the matlab search path, not the os search path which is relevant for executables. Either switch to the directory:

cd ('C:...\B')
system('example.exe')

or refer the executable with the full path

system('C:...\B\example.exe')

You may also modify the windows path variable and add C:...\B

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Thank you. I ended up with cd ('C:...\B') myfun() cd ('C:...\A') since more than 1 .exe's are called. – Z Cao Feb 04 '14 at 20:45
  • Use something like`p=pwd;cd ('C:...\B');myfun();cd(p);` instead. It returns to any previous set working directory. – Daniel Feb 04 '14 at 20:50
1

As @Daniel pointed out, I believe you're confusing the OS level path variable with the Matlab path. You might look into the getenv and setenv functions. In particular, you may be able to obtain you Windows path via

getenv('PATH')

There are also lower-level ways to do this via calls to system. Finally, you might also find this question helpful and maybe this one too.

Community
  • 1
  • 1
horchler
  • 18,384
  • 4
  • 37
  • 73