How to fix the errors Arise from moving .m files and functions in folders?

I wrote some codes in Matlab for classification and I achieved the desired results, all the functions which were used in the program exist in Matlab projects path in C drive in my computer but for running another clustering program in Matlab, I removed the .m files and functions from the Matlab's projects path and saved all of them as a folder in C drive.
Now my first program shows errors about some of these functions while It didn't have any problems with the function's codes before, even I returned files to the previous state but this problem still exists.
Should I put the required functions in the Matlab's projects path or in another folder?
I'll be grateful to have your opinions about how to fix these errors.

16 Kommentare

Have you tried adding those folders to the MATLAB Search Path?:
"...all the functions ... exist in Matlab projects path in C drive in my computer.."
Hopefully that does not mean that they were saved in the MATLAB installation folders.
What exactly do you call "Matlab's project path"?
"my first program shows errors" - this is not clear. Please post the relevant part of the code and the error messages. It is not possible to help you without knowing any details of the problem.
You can use different folders for different projects. Either with the GUI pathtool or with addpath and rmpath you can add folders to Matlab's path, such that the function in them are recognized. Moving files around is more complicated.
Thanks for your attention
I put the folder which consists of all the functions in the path: drive C->matlab->bin folder (matlab's projects path) and I put each of these functions in this path too
also I put this folder in my computer->drive C and Matlab program installed in this drive too.
Do you mean that this is the reason of the errors?
I didn't understand what is the Matlab search path.
@phdcomputer Eng: Please post the names of the folders exactly as they are defined. "drive C->matlab->bin folder (matlab's projects path)" is still vague. Is it: "C:\Matlab\bin\" or "C:\Matlab\R2019a\bin\" or "C:\Matlab\bin folder"? Where is Matlab installed - start Matlab and post the output of the matlabroot command.
I do not know, what "Matlab's project path" means.
If you do not understand, what Matlab's search path is, take a look into the documentation, e.g.:
doc path
This path contains the list of folders to search the M-files in. If a folder is contained in the path, Matlab finds them.
Never include user-defined function inside Matlab's installation folder. If you do so, changes are not recognized, because the files and folders of Matlab's toolboxes are added as "freezed" to the path. See: doc path, doc addpath, doc rehash
Thanks,
As you have said, I used matlabroot, the resault is:
C:\Program Files\MATLAB\R2016a
but I usually use C:\Program Files\MATLAB\R2016a\bin for saving my projects (that I mean Matlab's projects path)
Stephen23
Stephen23 am 17 Jun. 2019
Bearbeitet: Stephen23 am 17 Jun. 2019
Do NOT save anything under this folder:
C:\Program Files\MATLAB\
"but I usually use C:\Program Files\MATLAB\R2016a\bin for saving my projects"
Do NOT do that.
DO NOT save anything in any installation folders of any application.
Most MATLAB users save files to their personal directory, e.g. in the MATLAB default startup folder (depends on version):
Thank you very much
Ok so I should move all of the programs and functions (.m files ) in other drive except drive C (which Matlab has installed), for example drive D. Is It right?
Can Matlab find the new drive or I should define the new path for Matlab?
When I type pwd in command , the answer is :
C:\Program Files\MATLAB\R2016a\bin
As I explained, the folder that all the projects of matlab (.m files) exist. So how can I change pwd path for Matlab?
The function svmclassify :
[EDITED, Copyrighted code removed, Jan]
There is an error:
Error using svmclassify (line 56)
The first input should be a struct generated by SVMTRAIN.
for the line 56:
error(message('stats:svmclassify:TwoInputsNoStruct'));
I'll be grateful to have your opinions about how to fix this error.
Thanks
@phdcomputer Eng: Please do not post the code of functions of Matlab's toolboxes.
Note that this seems to be a new question. Then open a new thread.
The error message is clear: The first input must be a struct generated by svmtrain. So post, what you use as first input.
Did you solve the problem of the location of M-files? Cleanup the folder C:\Program Files\MATLAB\R2016a\bin. Working with admin privileges is a bad idea at all, because it is too easy to destroy the Matlab installation.
You can store the user-defined M-files where you want, but not inside the C:\Programs or C:\Windows folders. Where do you save your other documents?
Stephen23
Stephen23 am 18 Jun. 2019
Bearbeitet: Stephen23 am 18 Jun. 2019
"Ok so I should move all of the programs and functions (.m files ) in other drive except drive C (which Matlab has installed), for example drive D. Is It right?"
No. I never said that you have to use a different drive.
What I wrote is that you should NOT save any of your personal files/documents in any installation folders of any application (or your OS). The obvious place to save personal files is in your documents folder.
"I didn't understand what is the Matlab search path."
That is why I gave you the link to read. These explanations might help too:
Thank you all very much,
With the help of your instructions, the program was successfully implemented
The Matlab software installed on my computer(windows OS) shows a lot of errors when I tried to change the search path by using addpath command , suddenly MATLAB shows errors even for the startup and doesn't recognize any functions or variables or any commands
I usually saved my projects in C:\Program Files\MATLAB\R2016a\bin and when I tried to change the search path to C:\Users\Bita\Documents\MATLAB by using
addpath('newpath')
and also usnig
mypath=fullfile(userpath,'foldername')
addpath(mypath)
and then MATLAB is showing iterative errors while I'm not running any programs, even for MATLAB startup ,It shows a lot of errors
The errors are:
Undefined function or variable 'matlabrc'.
Undefined function or variable 'which'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.mathworks.mlwidgets.graphics.ModelStateFactory.createNoSelectionModelState(ModelStateFactory.java:251)
at com.mathworks.mlwidgets.graphics.PlotToolSetFactory$3.parseComplete(PlotToolSetFactory.java:123)
at com.mathworks.mlwidgets.graphics.ModelStateFactory$ProductInfoListener$1$1.run(ModelStateFactory.java:1032)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I'll be very grateful to have your opinions about how to fix MATLAB software
Thanks
Try using
restoredefaultpath
However when I look at the list of things that are failing, I suspect even restoredefaultpath might fail.
You might need to find pathdef.m and delete (or rename) it. And possibly you might need to rename or delete your prefdir directory.
Thanks
I used restoredefaultpath in command , as you have said, Matlab shows undefined function or variable
and for pathdef.m I searched I don't have this file , prefdir also shows the same error.
even MATLAB doesn't recognize clc in command.
Maybe the only way is reinstalling MATLAB software?
@phdcomputer Eng: I assume you have destroyed the Matlab installation. The clean solution is to uninstall Matlab, delete the installation folder, and to re-install it. Afterwards avoid working with admin privileges and do not write files in Matlab's installation folder.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Ok so I should move all of the programs and functions (.m files ) in other drive except drive C (which Matlab has installed), for example drive D. Is It right?
No. You use any drive you want including the one where matlab is installed.
What you mustn't do, and this is not specific to matlab, is store any of your code/documents/pictures/etc. under Program Files or any of its subdirectory. Similarly, don't put your files in the Windows directory.
Typically, Matlab would have created a directory for you to store your files in. You can see what it is by typing
userpath
at the matlab prompt. It normally is C:\Users\yourusername\Documents\MATLAB.
As for, I think I can use absolute path for functions so the errors will be fixed
I don't know what Suyraansh Mata really meant, but it is not an option for functions. You cannot call a function by its full path. Even for scripts it's a bit iffy, the only way to invoke them by their full path is to use run.
The proper way to manage the scope of your functions is to put their folder on the matlab path. So you'd put all your files in
mypath = fullfile(userpath, 'SomeMeaningfulFolderName')
then
addpath(mypath)
to make them all visible to matlab.

1 Kommentar

The Matlab software installed on my computer(windows OS) shows a lot of errors when I tried to change the search path by using addpath command , suddenly MATLAB shows errors even for the startup and doesn't recognize any functions or variables or any commands
I usually saved my projects in C:\Program Files\MATLAB\R2016a\bin and when I tried to change the search path to C:\Users\Bita\Documents\MATLAB by using
addpath('newpath')
and also usnig
mypath=fullfile(userpath,'foldername')
addpath(mypath)
and then MATLAB is showing iterative errors while I'm not running any programs, even for MATLAB startup ,It shows a lot of errors
The errors are:
Undefined function or variable 'matlabrc'.
Undefined function or variable 'which'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'fschange'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable
'internal.matlab.desktop.editor.isSystemObjectFile'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.mathworks.mlwidgets.graphics.ModelStateFactory.createNoSelectionModelState(ModelStateFactory.java:251)
at com.mathworks.mlwidgets.graphics.PlotToolSetFactory$3.parseComplete(PlotToolSetFactory.java:123)
at com.mathworks.mlwidgets.graphics.ModelStateFactory$ProductInfoListener$1$1.run(ModelStateFactory.java:1032)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I'll be very grateful to have your opinions about how to fix MATLAB software
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Suryaansh Mata
Suryaansh Mata am 17 Jun. 2019
TLDR: Any folder/directory can be added to MATLAB's path using the 'addpath' command.
MATLAB can access functions in the following ways -:
1) Direct access via a function's name - This is possible when the function .m file exists in the current working directory or the defined matlab path
2) Absolute Path - Accessing a function not in the current path, using it's absolute path. If trying to call a function using it's absoute path matlab does not throw any error
3) Adding a function or a directory to MATLAB's path - If a function is in Matlab's search path, it can be accessed directly. Try seeing if the current folder is in MATLAB's path using the 'path' command and seeing from the list that is generated. Or a directory can be added to this path using the 'addpath' command.
This can help with any errors while trying to access functions not in the present directory.

2 Kommentare

Thank you very much
As you have said, I think I can use absolute path for functions so the errors will be fixed, how can I define absolute path for the functions?
Just use the direct path like 'C:/Documents/MyFolder/myfunction.m' in case of Windows system or 'home/MyDirectory/myfunction.m' in case of Linux/Mac OS

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 17 Jun. 2019

Kommentiert:

Jan
am 19 Jun. 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by