path of a mfile not on search path

조회 수: 4 (최근 30일)
Bruno Luong
Bruno Luong 2019년 9월 30일
댓글: Bruno Luong 2019년 10월 9일
When an mfile is not on the search path or current path and when user types the name, MATLAB find it and issues a suggestion
>> foo
'foo' is not found in the current folder or on the MATLAB path, but exists in:
E:\matlab\test
Change the MATLAB current folder or add its folder to the MATLAB path.
Is there anyway to retreive the folder 'E:\matlab\test' programmatically?
  댓글 수: 2
Rik
Rik 2019년 10월 9일
I haven't tested this, but if I recall correctly the only folders that are searched are the folders in the drop down menu containing previous current working directory. There may be a way to retrieve that directory list and generate this suggestion yourself. You will probably need some Yair Altman level tricks.
Stephen23
Stephen23 2019년 10월 9일
편집: Stephen23 2019년 10월 9일
" There may be a way to retrieve that directory list..:"
Stored in prefdir, that shouldn't be too hard.

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

채택된 답변

Rik
Rik 2019년 10월 9일
As suggested in a comment here you can use the diary function to capture output to the command window.
  댓글 수: 3
Rik
Rik 2019년 10월 9일
But you do see the text? (I'm on mobile so I can't currently check myself)
Bruno Luong
Bruno Luong 2019년 10월 9일
Yes I see the eror message with the path, but I cannot use it since some one has to type
diary off on command window.
(My purpose is to retrieve this path and suggest in the diaglog box to user to confirm if he/she wants add the path to run FOO)

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

추가 답변 (1개)

Jyotsna Talluri
Jyotsna Talluri 2019년 10월 9일
You can get the folders using 'addpath' function
  댓글 수: 1
Bruno Luong
Bruno Luong 2019년 10월 9일
편집: Bruno Luong 2019년 10월 9일
My question is how to retreive the PATH name in the fix suggestion provided by MATLAB programatically.
I try try/catch lasterror, lasterr, etc... nothing seems to work. This error message seems to appear only when the mfile is invoked from the base workspace.

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by