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!



