Home > Software engineering >  Unrecognized function or variable
Unrecognized function or variable

Time:01-06

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.

CodePudding user response:

When you simply click Run, it's the same as running the command

ReadFileNames();

Note there are no inputs here, but your code expects (and requires) the input DataFolder.

So you have to do one of two things

  1. Click the drop-down by the Run button, edit the type code to run prompt and add your folder. Then you can continue to click the Run button to execute this again. Note that once you've edited the default Run command for a function, the Run button icon changes slightly to reflect it:

    run button

  2. A more common, and arguably more clear, way to run your function would just be to call it from the Command Window by typing ReadFileNames('your/folder/path/here'); (and hitting Enter to run).

    command window

  •  Tags:  
  • Related