# Temporarily remove mosek from matlab path to access overwritten optimization toolbox quadprog

## Alec Jacobson

## February 12, 2011

I've been using mosek from matlab, which redefines a number of functions (quadprog, optimget, optimset, etc.) that were originally functions from matlab's optimization toolbox. I wanted to compare the functionality and quality of mosek's quadprog vs matlab's quadprog, but this turned out to be a pain to do. Since I have all of the mosek paths at the top of my matlabpath, its versions are seen first thus the matlab versions are hidden. Even worse if all I want to do is call the matlab version of quadprog I **can't** simply get a handle to the matlab quadprog and call it since internally matlab's quadprog calls optimget and optimset which have also been overwritten by mosek.
If mosek is at the top of your path the you should be able to issue this:
```
which quadprog
```

and see something like:
```
/opt/local/mosek/6/toolbox/r2007a/quadprog.m
```

Thus the easiest solution was to temporarily eliminate mosek from the matlab path. This is possible programatically with:
```
% store original path so we can reset to it after we're done
old_path = matlabpath;
% split based on colon to obtain cell array of individual directories
dirs=regexp(old_path,':','split');
% only keep directories that don't contain mosek
new_dirs = dirs(cellfun(@isempty,regexp(dirs,'mosek')));
% append colons to each directory name and concatenate
new_path = cell2mat(strcat(new_dirs,':'));
% set matlab path to new path
matlabpath(new_path);
```

Now if you issue:
```
which quadprog
```

you should see something like:
```
/Applications/MATLAB_R2009aSV.app/toolbox/optim/optim/quadprog.m
```

**Update:** The above is especially useful when trying to use matlab's builtin optimization tools like `fminunc`

, which will otherwise call mosek's `optimset`

and crash with an error like:
```
Error using strfind
Inputs must be character arrays.
Error in fminunc (line 182)
flags.detailedExitMsg = ~isempty(strfind(display,'detailed'));
```