while~feof(inFile)
should not be relied upon to be accepted in future versions. You should use a space between the while and the condition.
You are using feof() as if it predicts end-of-file, as if after after the last item in the file is read, the I/O routines would look ahead and see that nothing is left and would set the feof flag. Anything based upon the C or C++ I/O libraries or upon the OpenGroup Unix Standards or upon the POSIX standards (and MS Windows claims POSIX conformance in this regard) never does that kind of "look-ahead". Instead, feof is not set until an I/O operation attempts to read data and there is absolutely no data available. Therefore, each time you fgetl() you need to test whether that was the I/O that found end-of-file. And it turns out that the easiest way to do that does not need feof at all:
while true
line = fgetl(inFile);
if ~ischar(line) %at EOF, non-char is returned
break;
end
index = index + 1;
end
I admit to being puzzled as to why you are not storing the content of the lines you read...
You initialize
student=[];
testQuestion=[];
If you do some testing, you will find that
if [] == -1
and
if [] ~= -1
are both false. Perhaps you meant to set student and testQuestion to something along the way, but we cannot tell what.