Hello Nick,
I am assuming that you are trying to run the script file directly by pressing the ‘Run’ button or executing the file from command window. For a file with function to run properly, you need to pass arguments.
You may refer the below documentation to pass arguments to functions with the help of ‘Run’ button:
You may also refer the below link to pass arguments to functions using command window:
Also, Array indexing starts from 1 in MATLAB. You may adjust your index values accordingly.