Path, Current Directory, "exist" and "which" functions

17 Ansichten (letzte 30 Tage)
Thomas Vanaret
Thomas Vanaret am 2 Dez. 2011
Hi
Here is my problem
If we consider two files whose path are :
  • studies_1\data\file.mat
  • studies_2\data\file.mat
were "studies_1" and "studies_2" are in the Matlab path, but not "studies_1\data" or "studies_2\data".
If Current Directory is "studies_1" or"studies_2" , following command :
exist('data\file.mat','file')
will return 2 (the file exist), but :
which('data\file.mat')
will return 'data\file.mat' not found.
So, how can I know exactly which file among "studies_1\data\file.mat" and "studies_2\data\file.mat" is considered by functions like exist or load when I use "data\file.mat" ?
Does it ONLY depend on the Current Directory?

Antworten (2)

Junaid
Junaid am 2 Dez. 2011
Dear I guess it depends on your current directory. Let say you are in studies_1/ directory. then
load ('data/file.mat');
this will load the file in studies_1/data. However in my system I can easily check
which('data/file.mat');
you try with both, forward and backward slashes. If you have further confusion then better to give full path in load time.

Walter Roberson
Walter Roberson am 2 Dez. 2011
The documentation for which says,
which file.ext displays the full pathname of the specified file if that file is in the current working folder or on the MATLAB path. To display the path for a file that has no file extension, type "which file." (the period following the filename is required). Use exist to check for the existence of files anywhere else.
Thus, "which" is not suitable for determining whether a file exists in a subdirectory.

Kategorien

Mehr zu Search Path finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by