Error writing to text file
Show older comments
Below is the code I am having issues with. The values for t and Q that are being writing onto the text file are wrong and I am not sure how to fix this.
fid= fopen('RCSimulation.txt','w');
fprintf(fid, '%% Time \t Q \t V \t i \n');
fprintf(fid, '%% (s) \t (C) \t (V) \t (Ohm) \n');
fprintf(fid, '%% ==== \t ==== \t ==== \t ==== \n');
for n=1:N
t(n+1)=t(n)+Dt; % Updates time vector
Q(n+1)=Q(n)+Dt*Qdot(t(n),Q(n)); % Calls the function f(t,Q) = Qdot
fprintf(fid,' %4.1f \t %6.1f \n', t, Q);
end
fclose(fid);
2 Comments
Guillaume
on 21 Mar 2017
So, what is being written and what should be written?
What is the contents of t and Q at the end of the loop? What is in written in the file?
Jan
on 21 Mar 2017
Please describe the issus you have. It is easier to solve a problem than to guess, what the problem ist.
Answers (0)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!