The name of a script

Normally we give a convenient name to a file. In octave, it is a little tricky. There are many function names which we call from our script. All these names may not be known to us while writing the script. If your file name is the same as that of one of the inbuilt functions, after interpreting, gnu-octave will give an error:

Consider the case when I wrote a script with the name “surface.m”. I didn’t know that such a function already exists. When I run this script on octave prompt, this error is displayed….

invalid use of script “/my octave work path/surface.m” in index expression

So I saved the script file with different name and then deleted the my earlier surface.m file. This worked. The reason is:

Every time you run your script on the octave prompt, gnu-octave first sees if any of the function files are in the same directory of your script directory. In my case it found “surface.m” but was not of the function it should contain.

For writing new script, now, the rule becomes:

Always prefer to give a name from the local language (in my case Marathi) so that there is no possibility of an inbuilt function of that same name !

The script is given below. Don’t name it as “surface.m”.


clear
clc()
x=[-2:0.1:2];
y=x;
[X Y]=meshgrid(x,y);
Z=X.^2-Y.^2;
surf(X,Y,Z)



prushtha

…and this is the output !