LCFactorization
LCFactorization

Reputation: 1712

How to overwrite an mexw32 without the need of restart Matlab?

When I am writing my own mex function in matlab, I have to debug it and check the mex function many times when running it in matlab's workspace.

Each time when I rebuild the mexw32/mexw64, I need to replace the old one with the new built before further testing in matlab environment.

However, there will always be an error message "Error copying file..., you may not have permission" if I don't restart Matlab before overwriting the old version.

1) what is the reason since I only run the mex function once and have already terminated it?

2) How can I overwrite the old mex file without restarting Matlab?

Thanks

Upvotes: 2

Views: 1297

Answers (1)

chappjc
chappjc

Reputation: 30589

You need to run:

 clear mex

That will unload all MEX-files from memory so you can overwrite or delete the files. You can also selectively unload MEX-files with clear mexFileName.

To list all loaded MEX-files use inmem as follows,

[~,mexLoaded] = inmem('-completenames')
mexLoaded = 

    'C:\Program Files\MATLAB\R2013b\toolbox\matlab\winfun\winqueryreg.mexw64'

Note that if a function was previously locked via mlock, it is necessary to unlock it with munlock or it will not be unloaded.

Upvotes: 5

Related Questions