Undefined function or variable
显示 更早的评论
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 个评论
Guillaume
2017-12-4
"even though I already set PATH for MATLAB"
Clearly, that did not work. How do you set the matlab path?
Walter Roberson
2017-12-4
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
2017-12-4
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
2017-12-4
Walter Roberson
2017-12-4
Download it into a directory, cd to the directory and try
run('testpath.m')
Walter Roberson
2017-12-4
编辑:Walter Roberson
2017-12-4
Please show the output of executing
which path
which matlabpath
matlabpath
inside MATLAB
Thao Ha
2017-12-5
编辑:Walter Roberson
2017-12-5
Walter Roberson
2017-12-5
Try
cd('C:\Users\Thao Ha\Documents\MATLAB')
ls('p*.m') + 0
and show us the output
Thao Ha
2017-12-5
编辑:Walter Roberson
2017-12-5
Walter Roberson
2017-12-5
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
2017-12-5
Walter Roberson
2017-12-5
What happens if you
cd('C:\Users\Thao Ha\Documents\MATLAB')
run('project.m')
Thao Ha
2017-12-5
编辑:Walter Roberson
2017-12-5
Walter Roberson
2017-12-5
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
2017-12-5
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
2017-12-5
回答(2 个)
KL
2017-12-4
You still haven't answered how you set the path. Use addpath,
addpath('C:\Users\MyName\Documents\MATLAB')
Walter Roberson
2017-12-5
0 个投票
You need to contact Mathworks for installation support.
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



