Undefined function or variable
Afficher commentaires plus anciens
When I tried to run the file "project.m" in the folder "C:\Users\MyName\Documents\MATLAB", it always showed the error "Undefined function or variable 'project'" even though I already set PATH for MATLAB to point to that MATLAB folder. I have a student license lasting till Oct 31, 2018
19 commentaires
Guillaume
le 4 Déc 2017
"even though I already set PATH for MATLAB"
Clearly, that did not work. How do you set the matlab path?
Walter Roberson
le 4 Déc 2017
Please show the output of:
folder = 'C:\Users\Thao Ha\Documents\MATLAB';
if ~exist(folder, 'dir')
fprintf('folder "%s" does not exist?\n', folder);
else
dinfo = dir( fullfile(folder, 'project*.*') );
if isempty(dinfo)
fprintf('folder "%s" does not have any project*.* files\n', folder);
else
fprintf('project*.* files in folder "%s" are:\n', folder);
celldisp({dinfo.name});
fprintf('\n');
end
dinfo = dir( fullfile(folder, '*.m') );
if isempty(dinfo)
fprintf('folder "%s" does not have any *.m files\n', folder);
else
fprintf('*.m files in folder "%s" are:\n', folder);
celldisp({dinfo.name});
fprintf('\n');
end
end
Walter Roberson
le 4 Déc 2017
You accidentally copied my code as 'dir ' instead of 'dir'. Also you copied
dinfo = dir( fullfile(folder, '*.m') );
as
dinfo = dir( fullfile(folder, '*.m ') );
I have attached the code as a .m file that you can download and run.
Thao Ha
le 4 Déc 2017
Walter Roberson
le 4 Déc 2017
Download it into a directory, cd to the directory and try
run('testpath.m')
Walter Roberson
le 4 Déc 2017
Modifié(e) : Walter Roberson
le 4 Déc 2017
Please show the output of executing
which path
which matlabpath
matlabpath
inside MATLAB
Thao Ha
le 5 Déc 2017
Modifié(e) : Walter Roberson
le 5 Déc 2017
Walter Roberson
le 5 Déc 2017
Try
cd('C:\Users\Thao Ha\Documents\MATLAB')
ls('p*.m') + 0
and show us the output
Thao Ha
le 5 Déc 2017
Modifié(e) : Walter Roberson
le 5 Déc 2017
Walter Roberson
le 5 Déc 2017
You have a space at the end of 'MATLAB ' in the test that worked. If that space is part of the directory name then you are going to confuse people including yourself.
cd('C:\Users\Thao Ha\Documents\MATLAB ')
is not the same as
cd('C:\Users\Thao Ha\Documents\MATLAB')
Thao Ha
le 5 Déc 2017
Walter Roberson
le 5 Déc 2017
What happens if you
cd('C:\Users\Thao Ha\Documents\MATLAB')
run('project.m')
Thao Ha
le 5 Déc 2017
Modifié(e) : Walter Roberson
le 5 Déc 2017
Walter Roberson
le 5 Déc 2017
Please go back to the testpath.m that I posted in https://www.mathworks.com/matlabcentral/answers/370999-undefined-function-or-variable#comment_512503 and download it to a directory, and cd to that directory, and
run('testpath.m')
KL
le 5 Déc 2017
What happens if you close matlab and double-click open your m-file from your file explorer. That should open the file with its corresponding folder as working directory.
Thao Ha
le 5 Déc 2017
Réponses (2)
KL
le 4 Déc 2017
You still haven't answered how you set the path. Use addpath,
addpath('C:\Users\MyName\Documents\MATLAB')
1 commentaire
Walter Roberson
le 5 Déc 2017
0 votes
You need to contact Mathworks for installation support.
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



