Effacer les filtres
Effacer les filtres

How to plot a graph from a text file saved in a for loop?

1 vue (au cours des 30 derniers jours)
Punit Gandhi
Punit Gandhi le 20 Avr 2015
Commenté : Adam le 20 Avr 2015
Hello everyone, I want to plot a graph from a text file which i save in my matlab code. The code goes something like this.
pause on
for i=1:50
% calculations %
.......
% saving a file %
name='output.txt';
fid = fopen(name,'a');
FORMAT = '%g ';
if i==1;
fprintf(fid, 'Date(m/d) Time(24hr) Carbon Money Grid Batt\n\n');
end
fprintf(fid,FORMAT,c_fc(2:3),c_fc(4),Carbon_saved(i),Money_saved(i), Grid(i), Batt(i));
fprintf(fid,'\n');
%%Plotting Graphs
if i<24
V=output(1:i,2);
U=output(1:i,5);
else
V=output(i-23:i,2);
U=output(i-23:i,5);
end
plot(V,U);
fclose(fid);
i=i+1;
pause(3600)
end
pause off
I want to draw a graph such that after every iteration it updates itself for last 24 values of the file. But this code gives error that "undefined variable output". Can someone help me in understanding how I can generate graph for the above condition. Also, I want to generate graph for the column 3 and 4 with respect to column 2. But, I think it will follow the same logic as before.
  1 commentaire
Adam
Adam le 20 Avr 2015
It's not obvious why a file needs to be involved since you are writing it rather than reading it.
'output' is not defined because it is just the name you assigned to a text file.
If you use a matrix variable, output , instead and remove all use of file it would be a lot simpler.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Networks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by