Undefined Function or variable Error

16 次查看(过去 30 天)
I tried a code with a filename jesuschrist.m. Always says Undefined function or variable 'jesuschrist'.
Any help is appreciated.
Thanks

回答(2 个)

Adam
Adam 2015-9-15
Is the file on your Matlab path? In order for Matlab to see it and run it it must be on your path.
  10 个评论
Walter Roberson
Walter Roberson 2015-9-15
Experiment with
run('D:\ADNI1 Screening 1.5T(1075)\code\jesuschrist.m')
Jab
Jab 2015-9-15
totally frustrating!!! reinstalled matlab. not yet fixed

请先登录,再进行评论。


Image Analyst
Image Analyst 2015-9-15
clear all doesn't matter - getting rid of that won't fix it as you found out.
Also, you did not get the error message "Undefined function or variable 'jesuschrist'."
You got the error message "Undefined function or variable 'fullFileName'." The reason is that once you started running jesuschrist, it hit that line and realized that fullFileName had not yet been defined by the time it needed to use it. Even after you fix that, you'll get the same problem with M because you did not define M either.
To fix, put this code right before your call to load():
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
  2 个评论
Jab
Jab 2015-9-15
编辑:Jab 2015-9-15
I am getting the error message
with the filename as Undefined function or variable 'jesuschrist'.
I have the other two files in the folder where the jesuschrist file exist
Walter Roberson
Walter Roberson 2015-9-15
No, fullFileName appears as a string in the posted code, not as a variable.
load fullFileName
is
load('fullFileName')
Of course if there is no .mat named literally fullFileName.m then there would be a problem.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by