Unrecognized function or variable

조회 수: 15 (최근 30일)
Kiran Yendamuri
Kiran Yendamuri 2021년 12월 28일
댓글: Kiran Yendamuri 2021년 12월 28일
Hello,
I'm trying to run the beginning of a script that was sent to me:
function [ FList ] = ReadFileNames(DataFolder)
DirContents=dir(DataFolder);
FList=[];
DataFolder is the name of the folder in which all my data is held. When I click the Run button I receive:
ReadFileNames(DataFolder)
Unrecognized function or variable 'DataFolder'.
And I'm not sure why?
Any help is much appreciated. Thank you.
  댓글 수: 2
DGM
DGM 2021년 12월 28일
Where is DataFolder defined? If you haven't defined it, you will need to do so.
Kiran Yendamuri
Kiran Yendamuri 2021년 12월 28일
Hi DGM,
I defined DataFolder, but still receive an error message:
function [ FList ] = ReadFileNames(DataFolder)
Error: Function definition are not supported in this context. Functions can only be created as local or
nested functions in code files.

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

답변 (1개)

Voss
Voss 2021년 12월 28일
Tell the program what your data folder is
DataFolder = 'C:\';
ReadFileNames(DataFolder)
ans = []
function [ FList ] = ReadFileNames(DataFolder)
DirContents=dir(DataFolder);
FList=[];
end
  댓글 수: 4
DGM
DGM 2021년 12월 28일
편집: DGM 2021년 12월 28일
If you're using a version older than R2016b, you can't have functions defined in a script. You didn't specify what version you're using, so I'll just throw that out there.
Kiran Yendamuri
Kiran Yendamuri 2021년 12월 28일
I'm using R2021b. I appreciate your time in helping me out here.

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

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by