1
votes

I'm beginning with octave. I've created a file called squareThisNumber.m in My Documents with the following code:

function y = squareThisNumber(x)
y = x^2;

I set the directory to look at My Documents with

cd 'C:\Users\XXXX\My Documents'

I type "squareThisNumber(3)" into octave, and all I'm getting is "Error: 'squareThisNumber' undefined near line 3 column 1." What am I doing wrong?

EDIT:

When I type ls into octave, I get "error: ls: command exited abnormally with status 127". Did I not install Octave correctly?

2
Welcome. You have to make sure the filename matches the function name and that the file is in the directory My Documents. - juliohm
Thanks, but as you can see both the filename and function name are matching, and the file is in the My Documents folder - user3204260
I can't reproduce the error. What version of GNU Octave are you using? We're at 3.8. - juliohm

2 Answers

2
votes

This behavior sure does seem like there's a problem with octave's current working directory. Does the command dir or pwd also have the same problem?

But you might be able to ignore all of that by

addpath("C:\Users\XXXX\My Documents");
1
votes

Did you place the end keyword at the end? Code example below works perfectly for me

https://saturnapi.com/fullstack/function-example

% Welcome to Saturn's MATLAB-Octave API.
% Delete the sample code below these comments and write your own!

function y = squareThisNumber(x)
y = x^2;
end

squareThisNumber(9)