Question

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?

Was it helpful?

Solution 2

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)

OTHER TIPS

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");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top