file_contents{i} = readFile('%d.txt', i);
You are passing two parameters to the
readFile
function, but it only accepts the first one. So when you try to call
fopen('%d.txt');
there is no such file, and the function returns -1. You then call
fscanf(-1, ...)
which fails as there is no such open file stream.
You need to change your
readFile
function to accept both parameters, and combine them to form a valid file name. You also need to check the value returned from
fopen
is not equal to -1, which indicates an error.