Undefined Function or variable Error

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일

0 개 추천

Is the file on your Matlab path? In order for Matlab to see it and run it it must be on your path.

댓글 수: 10

Jab
Jab 2015년 9월 15일
Could you please tell me how do I check whether it is in Matlab path or not? I saved the file on the D drive and runned it
which -all jesuschrist
You may have to use pathtool to add the directory to your MATLAB path.
Jab
Jab 2015년 9월 15일
편집: Walter Roberson 2015년 9월 15일
which -all jesuschrist
D:\ADNI1 Screening 1.5T(1075)\code\jesuschrist.m
This is the result i got
Jab
Jab 2015년 9월 15일
I have added using pathtool function. but still getting the same error
Walter Roberson
Walter Roberson 2015년 9월 15일
Is it a script or is it a function? If it is a function then what is the first line of the file?
Jab
Jab 2015년 9월 15일
편집: Walter Roberson 2015년 9월 15일
it is a script which contains the following
clc;
clear all;
close all;
load fullFileName;
load M;
Walter Roberson
Walter Roberson 2015년 9월 15일
You need to get rid of the "clear all"
Jab
Jab 2015년 9월 15일
i tried that too.still facing the problem
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일

0 개 추천

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
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

Jab
2015년 9월 15일

댓글:

2015년 9월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by