필터 지우기
필터 지우기

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 CenterFile Exchange에서 Networks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by