How to add a toolbox to the MATLAB path - matlab

Downloaded a library of functions from the internet. Drag and dropped it into the matlab directory (which is my default directory). I try to call these functions and nothing happens. They are several subfolders deep (matlab/fieldtrip/etc/etc). How do I access these functions from my workspace?

You should read the documentation that came with the toolbox since it may have toolbox-specific installation instructions. In your case it looks like you just need to add the fieldtrip directory to your path.
addpath('matlab/fieldtrip')
Then you'll have to run the ft_defaults install script that they provide which will theoretically handle all of those nested directories for you.
ft_defaults

Related

Error on a .exe that was running perfectly before being compiled

guys,
I just finished a particular code in MATLAB R2014a that reads and write into multiple text files and saves an image inside the same folder of the script. The script runs perfectly, but the compilation executable does not, so I believe that it has something to do with the PATH that the executable is trying to use to run, I don't really know.
The error was the folllowing:
That's the second read function in the code that tries to read a file and it's possible to see that the code was already successful doing a read/write operation, since a .txt is created.
Just to keep it simple, I didn't use any global paths to the files and tried to keep them inside of the script and executable folder.
I don't have a lot of experience compiling stuff, so I just used deploytool and hit run to test it, so I would love to hear some insights about the possible cause of the problem.
Thank you in advance for the help!
MATLAB doesn't include every file on your PATH when it compiles. It tries to detect additional files that may be accessed when running the code in your application's main file, and include those in the compilation, but it isn't always 100% successful (I'm not sure exactly what conditions it's unable to detect).
After you have run the deploytool once, the full list of files it has detected in this way will be listed under Files required for your application to run. You can add files to this list (whether or not your project has already been compiled) using the "+" icon in the corner of that section.

Installing add-ons without display

There are more and more packages on Matlab Central that are shared in the form of add-ons or custom toolboxes (extension .mltbx).
I'm using such toolboxes and when on my desktop I can simply install them by clicking on them. However my code is eventually deployed on a cluster, where none of the nodes has these toolboxes installed and none of the Matlab instance is run with display.
How can I install add-ons programmatically?
Poking around MATLAB's subroutines I couldn't figure out an obvious way to handle this programmatically without at least some user input.
That being said, the *.mltbx package is really just a *.zip file, which we can access directly inside MATLAB. To illustrate this, I've created a quick toolbox using my code prototyping folder, testcode-matlab.mltbx.
If you extract the contents of this file using unzip: unzip('testcode-matlab.mltbx', 'temp'); you should be left with something like the following:
If we examine the contents of fsroot, we see that it's the folder of data packaged into the toolbox:
So we can take this folder, move it to where we want using something like copyfile, and then add it to the MATLAB path using addpath:
copyfile('.\temp\fsroot', '.\mytoolboxes\testtoolbox');
addpath('.\mytoolboxes\testtoolbox');
As of R2016a, there is a MATLAB API to install them:
matlab.addons.toolbox.installToolbox('mytoolbox.mltbx')

Matlab: search path locked for editing?

I have written some database management software in Matlab. Occasionally data is labeled incorrectly and must be moved manually using windows explorer. All of the folders of the database are in the matlab search path via addpath(DataBaseRootDir). When one attempts to move or delete a folder in the search path, windows gets stuck waiting for Matlab to stop accessing the folder.
Is there a way to prevent this programmatically? It is always possible to close Matlab, make chances, and re-open the software but this is sub-ideal.
Thanks!
http://de.mathworks.com/help/matlab/ref/rmpath.html
rmpath(DataBaseRootDir)
Be aware that like addpath this will only remove the directory, but leave any subdirectories in the path, so if the directory has subdirectories that are also in the path, you would need to remove them as well.

Manually Adding Toolbox to Matlab R2013b

I am working with OS X version 10.9.4 and using Matlab R2013b. I have recently downloaded a toolbox file and it saved as a folder on my desktop. It contains a bunch of .m files, which I'm not really sure how to add into my Matlab. I've read online and watched a few tutorials that all mention that I need to set the path to Matlab, but I can't seem to get it to work for me. I'm very new to Matlab and have been trying to figure this out for a couple of days, so my apologies if this is a very simple question to be asking.
There are a couple of ways of doing this. When a function is called in Matlab, it will look in all the directories contained within the path to find it. You can bring up the path by typing in the command "path".
Presumably, you want to add a new location for Matlab to look. This can be done via the addpath command. Addpath accepts both relative and absolute addresses. For example the command
addpath('C:\My_Matlab_Functions')
will enable you to access functions & files within the folder My_Matlab_Functions.
Relative directories are taken relative to the file which calls addpath. For example if I am running a function within C:\users\user_name\My_Documents\Matlab, calling
addpath('Tools')
will enable you to access all of the files within C:\users\user_name\My_Documents\Matlab\Tools. You can also go up directories via '..'. For example, if I am running a function within C:\users\user_name\My_Documents\Matlab\Project1, the command
addpath('..\Tools')
Accesses the same tools folder as before.
I have tried these examples on Windows, but I presume they work the same on a Mac. Hope this helps.
Alternatively, you may be able to add your file(s) directly into Matlab's built in toolbox. I don't know whether Matlab automatically searches for new folders here, but it may be worth a shot.

error while loading shared libraries: libboost_system-mt-1_49.so.1.49.0

I'm a beginner MATLAB and C++ user and trying to run some code provided to me. The code
The error I get is:
/path/folder: error while loading
shared libraries: libboost_system-mt-1_49.so.1.49.0: cannot open shared object
file: No such file or directory
The folder exists and the file it's trying to call is in there. I just don't understand what this error is saying with the libboost library?
If I need to provide any of the code that calls the folder, let me know. Not sure how much info to provide.
I assume you have solved the problem. However I see it might still be useful to put some hints here as I see many posts asking for similar questions without being answered.
The solution is to add the library path into your system environment variables. Unfortunately it does not help to set it up outside Matlab (I mean edit the .bashrc in Ubuntu etc.).
The correct way is to use the Matlab's functions of reading and setting environment variables: getenv() and setenv().
Suppose the library file is located at: /home/username/lib/, so you will need to write in your Matlab scripts:
setenv('LD_LIBRARY_PATH',[getenv('LD_LIBRARY_PATH') ';/home/username/lib']);
I am using Linux, however, I think you could solve the problem similarly in other OSs.