Although you don't explicitly say so in your question, it looks like you wrote
mean = mean(T);
When I tried that, it worked the first time I ran the code but the second and subsequent times it gave the same error that you got. What seems to be happening is that the first time you run the script it calculates the mean of T
, which is a scalar, i.e. it has dimensions 1x1, and then stores it in a variable called mean
, which then also has dimensions 1x1. The second time you run it, the variable mean
is still present in the environment so instead of calling the function mean()
Octave tries to index the variable called mean
using the vector T
as the indices. The variable mean
only has one element, whose index is 1, so the first element of T
whose value is different from 1 is out of bounds. If you call your variable something other than mean, such as, say, mu
:
mu = mean(T);
then it should work as intended. A less satisfactory solution would be to write clear all
at the top of your script, so that the variable mean
is only created after the function mean()
has been called.