Function fopen - file function:
The permission string in the call to the fopen function identifies that the file is opened for writing to it. Just as when reading from a file, the answer from fopen and fclose must really be checked to make sure that they were successful. The fopen function tries to open the file for writing. If the files already exist, the contents are removed so it is as if the file had not existed.
When the file does notpresently exist (that would be the norm), a new file is generated. The fopen could fail, for illustration, if there isn't space to generate this new file.
To view what was written to the file, we could then open it and loop it to read each line by using fgetl:
>> fid = fopen('tryt.txt');
>> while feof(fid)
aline = fgetl(fid)
The loop variable is 1
The loop variable is 2
The loop variable is 3