How to correct “Function definitions are not permitted at the prompt or in scripts”

Matlab expects functions to be in their own file. Copy the above code to a file ‘stat.m’ and it should work.

This policy does cause an unnecessary number of short files, but it is required because of the way matlab handles variable scope. Each file gets its own scope, and all variables in the command prompt have global scope.

Leave a Comment