On 2/13/2012 4:52 PM, ImageAnalyst wrote:
> I agree. Once Brett Shoelson at the Mathworks told me to put this at
> the start of my code:
> % Change the current folder to the folder of this m-file.
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
>
> I think it maybe used to work but now it doesn't. It asks me to
> change directory, or add to path before the m-file even runs and gets
> to that code.
When I add the above code, it did CD, after I run the function,
and it did NOT ask me anything. after I run it, I found that
my folder was changed from the one I started from, which
is C:\Users\me\Documents\MATLAB
However, this solution means I have to 'run' a function, just
to cd to the folder it is in. What If I do not want to run it?
I just wanted to cd to that folder first, may be to check that
I have some data files in there, or for some other reason.
You solution helps, but I think Mathworks needs to come up
with a designed solution build-into the editor system itself.
> I've put in a request to have an option to do some kind
> of an auto-switch to the folder where your m-file lives when you try
> to run it but I don't think they liked that idea, so we are stuck with
> the annoying prompts all the time.
Again, I did not get the prompt. I am using 2010a on windows.
>
> I'm not sure your suggest solution is any better than the current
> situation of just running the file and then clicking "change folder"
> when the popup comes.
Except my solution would not require one to run the function first
in order to cd to the folder the function is located in.
regards,
--Nasser