Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octave error filename undefined near line x column y

Tags:

octave

I am trying to run an Octave file which is in the working directory, but I get an error. Octave does not seem to recognize that it should run the file.

unknown@unknown> dir
.                       ex1data1.txt            plotData.m
..                      ex1data2.txt            submit.m
computeCost.m           featureNormalize.m      submitWeb.m
computeCostMulti.m      gradientDescent.m       warmUpExercise.m
ex1.m                   gradientDescentMulti.m
ex1_multi.m             normalEqn.m

unknown@unknown> ex1
error: `ex1' undefined near line 21 column 1

unknown@unknown> ex1.m
error: `ex1' undefined near line 22 column 1

Can anyone advise how I can run the ex1 file?

like image 615
Timothée HENRY Avatar asked Oct 31 '13 09:10

Timothée HENRY


3 Answers

This fixed the problem [at least for me, on Windows]:

Entering the following command in Octave:

>addpath(pwd)

before calling the script:

>ex1

There is more info here.

like image 129
Timothée HENRY Avatar answered Nov 18 '22 19:11

Timothée HENRY


Octave (I'm on 4.0.3) will return this error (undefined near line 1 column 1) if you have a capital letter in your path anywhere. For example, if you have a folder on Windows, with the name d:/Myfolder/octave and then you write this:

cd d:/myfolder/octave (note the small "m")

Then octave will fail.

You have to write exactly the windows path:

cd d:/Myfolder/octave

and octave will be fine

like image 40
hh2000 Avatar answered Nov 18 '22 19:11

hh2000


You need to also save the file as "fileName.m"

Octave doesn't recognize 'fileName.M'. It has to be a lower-case '.m' extension

like image 1
Bwaxxlo Avatar answered Nov 18 '22 20:11

Bwaxxlo