Installing add-ons without display - matlab

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')

Related

How to link MATLAB to Webots lib?

I created a MATLAB script for controller through wizards and uncommented
desktop; keyboard;
to interact with the MATLAB interface. Works are done on Win10.
My code works, but I have to start the MATLAB program from Webots to grant MATLAB access to Webots library. I tried opening MATLAB alone and had no clue about linking the program to Webots lib and project.
Another drawback is that every time I modify the codes and reset the simulation in Webots, MATLAB is restarted, which is annoying since it takes quite a time.
Q: Is there any way to link MATLAB to Webots lib so that I can develop the controller in MATLAB alone without starting Webots?
Maybe below solve your problem.
Solution
In the launcher.m file (..\Webots\lib\controller\matlab):
Change each line containing 'lib/matlab' to 'lib/controller/matlab'
Lines are 15, 23, 132
and
In allincludes.h (..\Webots\lib\controller\matlab):
Change each include path so that it goes back a further directory
eg: #include "../../../include/controller/c/webots/accelerometer.h"

Matlab openGL Warning

I'm tasked with upgrading a lot of legacy models and scripts made in an older version of Matlab/Simulink and have it running smoothly in R2018b. Among other requirements I'm not allowed to have any warnings issued upon execution of .m scripts or Simulink models. This is generally tedious but straightforward to comply.
However, there is a specific warning that Matlab does not give me hints on possible sources:
Warning: MATLAB has disabled some advanced graphics rendering features by switching to software OpenGL. For more information click here.
The link opens the Matlab Help page titled Resolving Low-Level Graphics Issues, which describes issues I'm not finding (or at least not noticing)
I do note that many scripts I run create and close figures, but this is done procedurally. I haven't been able to associate this warning with some specific function or feature. I'm working on a Windows Server machine.
Does anyone have an idea of how to narrow down which kind of function os Simulink block could cause this warning?
As datenwolf and Ander point out, the first thing to try is to update your drivers. If this doesn't work, and your only problem is that you're getting the warning but your graphics still render fine, then you have two other options to try.
First, you can simply modify your OpenGL rendering preferences using opengl. The following will set your preference to 'software' and save that setting for future sessions:
opengl('save', 'software');
Alternatively, you can just try to suppress that particular warning message. After you get the warning, issue this call to the warning function:
w = warning('query', 'last');
The w.identifier field will give you the ID for the warning message, which I believe will be 'MATLAB:hg:AutoSoftwareOpenGL' in this case. You can then add the following line to your startup.m file so that this warning is suppressed every time MATLAB is opened:
warning('off', 'MATLAB:hg:AutoSoftwareOpenGL');
Install the original vendor drivers for your GPU. The drivers that are installed by Windows by default lack full OpenGL support. Download the driver package directly from the website of Intel, AMD or NVidia, depending on what GPU you have.
If you don't have GPU, for example when running in a Virtual Machine, then you can not avoid that warning, because then Matlab has no other choice than falling back on the software OpenGL implementation that it ships with.
There's nothing you can do about that, other than making sure, that the system you're running Matlab on, does have proper OpenGL support!
It took me a long time to get it, so I'll put you here in case it helps how I managed to activate openGL in Linux:
If you haven't already (it's common for other problems), rename libstdc++ library from MATLAB:
mv _YOUR_MATLAB_ROOT_FOLDER_/sys/os/glnxa64/libstdc++.so.6 _YOUR_MATLAB_ROOT_FOLDER_/sys/os/glnxa64/libstdc++.so.6.bak
Create this link: sudo ln -s /usr/lib/x86_64-linux-gnu/dri/ /usr/lib/
Run export MESA_LOADER_DRIVER_OVERRIDE=YOUR_DRI_DRIVER;matlab -desktop -nosoftwareopeng
Your DRI Driver will be a file from /usr/lib/dri, removing "_dri" (in my case was the "radeons" driver for an AMD Vega graphic card.
Run MATLAB from a terminal using: export MESA_LOADER_DRIVER_OVERRIDE=_YOUR_DRIVER_HERE_;matlab -desktop -nosoftwareopengl. YOUR_DRIVER_HERE should be your driver, radeonsi in my case.
Check openGL with info = rendererinfo
If something went wrong, you will be able to see in the terminal which library was responsible. Executing 4) and 5) I was discovering what I had to correct, you can do the same if you have another problem that has not appeared to me.
So that it always runs correctly I put export MESA_LOADER_DRIVER_OVERRIDE=YOUR_DRI_DRIVER at the beginning of the script that runs matlab (_YOUR_MATLAB_FOLDER/bin/matlab), although I suppose it can also be set as an environment variable.
I hope this has been useful to you.

How to add a toolbox to the MATLAB path

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

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.

Accessing any folder from a compiled MATLAB application

I am developing a windows stand alone application in MATLAB 2012b .
In the code I am writing some files in two folders images and dump which are both accessible to the user. I want those two folders to be in the same folder as the final executable. I can create those folders manually. However, when I run the compiled application, it does not seem to access those folders. For example, the following line of code works perfectly when run from inside MATLAB,
save(fullfile('./images/camp.mat'),'camp','-v7.3');
however it does not seem to work in GUI as it seems to stop working at that point only and nothing is created in the images folder.
I have searched through the internet and found things like ctfroot() and MCR_ROOT etc but I am not able to solve my problem.