exist function says directory figures exists when it doesn't

12 ビュー (過去 30 日間)
Leo Simon
Leo Simon 2020 年 8 月 5 日
コメント済み: Leo Simon 2020 年 8 月 5 日
For some reason, even though the directory figures does not exist, the command
exist('figures','dir')
is returning a 7 instead of a zero. I assumed this had to be something to do with my startup setup, but it appears not to be.
Could somebody explain why this is happening please?
I'm running R2019b on ubuntu 18.04
  2 件のコメント
Les Beckham
Les Beckham 2020 年 8 月 5 日
I see the same thing on my 2020a installation. Seems a bit strange. However, using the command
>> what figures
Packages in folder C:\Program Files\MATLAB\R2020a\toolbox\matlab\connector2\figures
connector mls
I see that figures is found on the Matlab path in a toolbox folder.
Apparently, if you are trying to detect whether 'figures' is a subfolder of the current folder you need to do this:
>> exist('.\figures', 'dir')
ans =
0
The doc on exist doesn't make it clear that it searches the entire Matlab path for any folders with that name but it seems that that is what it does.
Stephen23
Stephen23 2020 年 8 月 5 日
"The doc on exist doesn't make it clear that it searches the entire Matlab path..."
https://www.mathworks.com/help/matlab/ref/exist.html: "MATLAB searches starting at the top of the search path, and moving down until a result is found..."

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 5 日
Use isfolder(), R2017b or later. isfolder() does not search along the MATLAB search path.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by