Friday, January 8, 2010

Setting Path Straight in Matlab

Setting Correct Path in Matlab can be tricky as your program evolves to have similar folder structures and filenames.
Just learned how to set the path from Shortcut... wanted to share.


The following code helped me to set the path before I start the functions running...



mypath = pwd

mypath =

/home/../../directory-running

>> path(path,mypath)


Having a shortcut shall not hurt!

2 comments:

Steve said...

There are safer ways to do that. Look at the ADDPATH function; if you do that, you won't need to store the current directory in another variable.

addpath(pwd)

I also would avoid using "clear all" inside your shortcut, as the one in your image does, as that will clear not just the variables you created inside the shortcut but ALL of them that exist in the workspace when you invoke the shortcut. CLEAR ALL also clears breakpoints, which is another reason to avoid it unless you really need that big a hammer.

N K M said...

@Steve, thanks for your note.
I intended it to use @ the beginning of the session with different folders to handle every session.
Adding path by addpath is permanent while this is temporary way of setting path (only stays for the session) if you have many projects to deal with, this is easier.
I agree that it should just be clc instead of clear all.

Anyways, thanks!