Error writing to text file

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 comentarios

Guillaume
Guillaume el 21 de Mzo. de 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
Jan el 21 de Mzo. de 2017
Please describe the issus you have. It is easier to solve a problem than to guess, what the problem ist.

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Preguntada:

el 21 de Mzo. de 2017

Comentada:

Jan
el 21 de Mzo. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by