How to change the MATLAB path back to the default? - matlab

I was trying to add a toolbox in MATLAB and instead of calling addpath('path'), I called path('path').
Now I'm getting a lot of errors, like
if I initialize a variable, I get
Error using eval. Undefined function 'workspacefunc' for input arguments of type struct
Is there anyway I can restore the default MATLAB path/paths ?

Use the MATLAB command
restoredefaultpath
to restore the MATLAB search path to the state at startup.
See MATLAB documentation for restoredefaultpath here

I had a similar situation where on startup, on Windows 8.1 64-bit, Matlab R2014b would show the same error and then no function would work.
In my case, restoredefaultpathcouldn't be found.
Setting the UserPath in the matlab setting file as suggested elsewhere also didn't help.
The solution was to remove the environment variable MATLABPATH that I had set as a convenience while trying to compile against Matlab libraries.
The error message could be more helpful...

Related

How to locate where a built-in function is defined?

In MATLAB, there are roughly 3 ways to define functions: non-comment-only .m files, .p files, and compiled code (e.g. DLL, MEX).
Knowing where a function is defined could be helpful in several cases, such as when a breaking change was introduced to some function outside our control, and we'd like to try to revert to an old version in the hopes of getting our code working again; or when trying to reverse-engineering some undisclosed algorithm.
The which function is usually very good at identifying function definitions and their locations (which works for .m, .p and MEX), but isn't very useful when it comes to shared library functions, where (at best) it points to a comment-only documentation file:
>> which _mcheck
built-in (undocumented)
>> which svd
built-in (D:\Program Files\MATLAB\R2019a\toolbox\matlab\matfun\svd)
If so, assuming a function found within a shared library is called during the execution of my code, how can I locate the specific file (DLL) that contains it?
It turns out that dbstop can be used for this. For example:
>> which svd
built-in (D:\Program Files\MATLAB\R2019a\toolbox\matlab\matfun\svd)
>> dbstop svd
Warning: Entering debug mode is only supported within running MATLAB code files.
Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwmathlinalg>svd" is not a MATLAB code file.
Instead, the debugger will stop at the point right before "libmwmathlinalg>svd" is called.
From there's it's just a matter of finding a file called libmwmathlinalg (with the relevant extension) - which isn't a difficult task if your drive is indexed.

Elusive MATLAB built-in function

I am trying to read the following internal MATLAB function:
>>which visionInitializeAndExpandCheckerboard
built-in (C:\Program Files\MATLAB\R2015a\toolbox\vision\vision\visionInitializeAndExpandCheckerboard)
But it appears to be hidden away! And very well hidden.
None of the following methods to access it have worked:
Highlighting the name and pressing Ctrl+D.
Typing "edit visionInitializeAndExpandCheckerboard" in the command line.
Searching for the file in Matlab's own FindFiles.
Searching for the file on the disk.
Trying to Step Into the function in debug mode (I just get the output as if I had requested Step Out instead).
Btw, the reason I am looking into this is that the parent function detectCheckerboardPoints has seriously declined in performance from R2015a to R2016b and I am trying to figure out why.
The internal function is compiled native code, so you will not be able to see its source. If you see a performance degradation, you should call Mathworks tech support and complain. If it is something they can fix, they will send you a patch, and fix it in the next release.

Error in Compiled exe, but running in m file MATLAB

I have build a program that run properly in m file MATLAB. but when I compile to exe using Matlab compiler, some function didn't work. here is the error command window show on matlab execute program
undefined function or method 'maple' for input arguments of type 'char'
error in ==> function_a at 5
codes on function_a.m is
function function_a(msg)
format long
%parameter p & q
maple('z1:=',randint(1,1,[12 20])); %these run in m.file, but not in exe compile
p=maple('nextprime(z1)');
p=str2double(p);
is there any solution for that?please need your advice, many thanks
Assuming you have tried to compile the version from exactly this sourcecode and that you call it twice with exactly the same input, it appears that MATLAB simply does not realize that the function maple will be used by you.
I have had this before with some project, eventually I decided to use the 'add additional resource to project' option in deploytool.
Depending on your needs you can either just add the function, or the folder containing this function.
The command maple is from Symbolic Toolbox, which is not supported by MATLAB Compiler. You will not be able to successfully compile and run your program.
What's happened is that the maple command is not allowed to be compiled, so when the .exe runs, it can't find the function maple, and gives you the error you're seeing. It would be nice if MATLAB gave you a more informative error message, but it seems it doesn't.

How do I use the lteRMCDL tool?

I'm following an example from MathWorks.
When I run the code I get an erroneous output
Error in Untitled3 (line 38)
rmc = lteRMCDL(enb, ncw);
If the error you describe was preceded by:
Undefined function 'lteRMCDL' for input arguments of type 'struct'.
Then the most likely reason is that you do not have the LTE system toolbox, or that you have an older version which does not contain that function.
You can check which version of MATLAB you are running, and all the installed toolboxes you have along with their version number, by typing ver at the command line. Alternatively , you can check the location of a given function on the path by typing which lteRMCDL (this can help if the problem is that you have written a function with the same name as an existing MATLAB function, or if your MATLAB path is not set up correctly).
MATLAB online help shows by default the latest (2013b at time of writing) help and requires you to log in to show archived help files.

Why a command like combnk(1:3,2) does not work in Matlab 2011a?

Does anyone know why one can't use the command
combnk(1:3,2)
in Matlab 2011a, or is there any way to make this built-in function working? The error message I got is
???Undefined function or method 'combnk' for input arguments of type 'double'.
The two most common reasons for Undefined function or method-errors are (1) typos, and (2) lack of the appropriate toolbox.
If you're sure you didn't make any spelling mistake, try ver on the command line to check which toolboxes you have installed. If the statistics toolbox is missing, there won't be combnk on the path.
additional tip by Colin T Bowers
If ver indicates you do have the statistics toolbox, then try which combnk. If this returns combnk not found, then you may need to refresh your path, with something like restoredefaultpath then savepath