Unrecognized function or variable

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 comentarios

DGM
DGM el 28 de Dic. de 2021
Where is DataFolder defined? If you haven't defined it, you will need to do so.
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.

Iniciar sesión para comentar.

Respuestas (1)

Voss
Voss el 28 de Dic. de 2021
Tell the program what your data folder is
DataFolder = 'C:\';
ReadFileNames(DataFolder)
ans = []
function [ FList ] = ReadFileNames(DataFolder)
DirContents=dir(DataFolder);
FList=[];
end

4 comentarios

Hello Benjamin,
After assigning a path to DataFolder and running the code, I receive this:
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.
John D'Errico
John D'Errico el 28 de Dic. de 2021
You are still trying to run your function, as if it was a script. You even called it a script, and said you are clicking the run button. This is a function.
DGM
DGM el 28 de Dic. de 2021
Editada: DGM el 28 de Dic. de 2021
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 el 28 de Dic. de 2021
I'm using R2021b. I appreciate your time in helping me out here.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Dic. de 2021

Comentada:

el 28 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by