help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need Help Loading Functions


From: Philip Nienhuis
Subject: Re: Need Help Loading Functions
Date: Thu, 30 Aug 2012 07:47:44 -0700 (PDT)

adi89 wrote
> 
> Hi guys,
> 
> I just started using Octave recently.
> 
> 
> I made a text file with
> 
> "function [y1,y2]= squareAndCubeThisNumber(x)
> 
> y1= x^2;
> y2=x^3;"
> 
> And that's it in a txt file saved as "squareAnd CubeThisNumber.m"
> 

There's a space in the name.
Identifiers cannot have embedded spaces.



> I saved it to a folder, which is the directory recognized by Octave when i
> type pwd.
> 
> C:\Users\etc.
> 

"C:\Users\..." So you're on Windows. It always helps to tell what Octave
version and what operating system you use.



> when I try to call upon the function, Octave says it's undefined, yet the
> file in in the appropriate folder. 
> 

How did you call it?

squareAnd CubeThisNumber   ## (Note: space in file name)
  -or-
squareAndCubeThisNumber    ## (No space in name)
?

In the first case, Octave thinks you call some variable or function
"squareAnd". If you think you can outsmart Octave by surrounding it with
quotes, you're out of luck as Octave will simply think it is text input and
do nothing with it.
In the second case, Octave will look for a variable, function or function
file name "squareAndCubeThisNumber" (w/o space) but won't find that very
name as the disk file has another name (with an embedded space).

Embedded spaces in identifiers including file names, especially script file
names, is a recipe for trouble.
In file names you can sometimes get away with it if you assign the file name
to a char variable and invoke an I/O function on that char variable.



> I'm getting frustrated, because I thought Octave recognizes these files in
> the corresponding directory. I'm not sure what's wrong.. Would appreciate
> some input.
> 

Just do not use space(s) in variable / file / function names.

Philip




--
View this message in context: 
http://octave.1599824.n4.nabble.com/Need-Help-Loading-Functions-tp4643486p4643512.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]