Octave Function Undefined

Viewed 271

Any idea why the following produces an error?

printf("this is my text\n");

MyFunc;

function MyFunc
  printf("printing from inside function\n");
endfunction

This is the error I get (from the Command Window)

error: 'MyFunc' undefined near line 3, column 3 error: called from function_example at line 3 column 1

1 Answers

Okay, I see the issue now. The function definition needs to be placed before the function call is made - as shown below.

printf("this is my text\n");

function MyFunc
  printf("printing from inside function\n");
endfunction

MyFunc;
Related