フィルターのクリア

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

1 回表示 (過去 30 日間)
Punit Gandhi
Punit Gandhi 2015 年 4 月 20 日
コメント済み: Adam 2015 年 4 月 20 日
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 件のコメント
Adam
Adam 2015 年 4 月 20 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeNetworks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by