Real Time Matlab Graphing
조회 수: 3 (최근 30일)
이전 댓글 표시
I have an excel file that updates every minute and I imported it into matlab with this code...
fid=fopen('CR1000_PU22_TTT_15sec_new1.csv');
c=textscan(fid,'%s %f %f %f %f %f %f %f %f %f %f %f','CommentStyle',...
{',,Min,Smp,Avg,Avg,Avg,Avg,Avg,Avg,Avg,Avg'},...
'delimiter',',','EmptyValue',nan);
c{1,1}=strrep(c{1,1},'UTC','');
CR1000_PU22_TTT_15sec.time=datenum(c{1,1},'dd/mm/yyyy HH:MM');
CR1000_PU22_TTT_15sec.HF_Highest=c{1,5};CR1000_PU22_TTT_15sec.HF_Middle=c{1,6};CR1000_PU22_TTT_15sec.HF_Low=c{1,7};
CR1000_PU22_TTT_15sec.TC_Highest=c{1,8};CR1000_PU22_TTT_15sec.TC_Middle=c{1,9};CR1000_PU22_TTT_15sec.TC_Low=c{1,10};
CR1000_PU22_TTT_15sec.TC_Wall_Surface=c{1,11};CR1000_PU22_TTT_15sec.TC_Plenum_Air=c{1,12};
clear c fid
...so the data is in a structure. If the excel data is constantly being updated. Can I make a graph that is constantly changing with the new data as well. If so how would I do this?
댓글 수: 0
채택된 답변
John Petersen
2012년 7월 26일
편집: John Petersen
2012년 7월 26일
Here's an example of plotting one parameter. You don't really need the comparison of datenum with current since I put in a pause of 60s, but it is a check to see that the file really was updated. pos is used to read the file to the next line of data. I'm assuming the new data is appended to the file, which is why I increment pos each time. Not sure if this will load down your computer, but I'm hoping pause is really a sleep task:
pausetime = 60;
dirname = 'c:\myCR1000data\'; % example of directory
filename = 'CR1000_PU22_TTT_15sec_new1.csv';
file = dir(filename);
current = file.datenum;
f = figure;
pos = 1; % initial data line in file
while(1)
file = dir(filename);
if (file.datenum > current)
fid=fopen(filename);
c = textscan(fid,'%s %f %f %f %f %f %f %f %f %f %f %f',...
pos,...
'CommentStyle',...
{',,Min,Smp,Avg,Avg,Avg,Avg,Avg,Avg,Avg,Avg'},...
'delimiter',',','EmptyValue',nan);
fclose(fid);
pos = pos + 1;
c{1,1}=strrep(c{1,1},'UTC','');
CR1000_PU22_TTT_15sec.time = datenum(c{1,1},'dd/mm/yyyy HH:MM');
CR1000_PU22_TTT_15sec.HF_Low = c{1,7};
plot(f,CR1000_PU22_TTT_15sec.time, CR1000_PU22_TTT_15sec.HF_Low);
hold(f, 'on');
end
current = file.datenum;
pause(pausetime);
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!