Nevermind. I found out the problem. I moved the original fopen(file1) and fopen(file2) to within the if statements.
I still don't know why this solved the problem...they shoulld still be all closed anyway in my attached code.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!