필터 지우기
필터 지우기

Plotting Temperature with respect to time in MATLAB from a file??

조회 수: 3 (최근 30일)
Arun Sharma
Arun Sharma 2013년 10월 7일
댓글: Arun Sharma 2013년 10월 10일
Hello!!! Everyone,
I am making a Data Logger Project and had stored Log in Memory Card, and wants to plot the Temperature Data with Respect to time in MATLAB.
18:41:03,05/10/13,025.7C,+024.5C,060.0%,000.00m/s,0,0000.0mm,0000.0mm
18:41:17,05/10/13,025.7C,+024.8C,060.0%,000.00m/s,0,0000.0mm,0000.0mm
18:41:32,05/10/13,025.4C,+024.8C,059.3%,000.00m/s,0,0000.0mm,0000.0mm
18:41:48,05/10/13,025.7C,+025.1C,059.3%,000.00m/s,0,0000.0mm,0000.0mm
18:29:50,05/10/13,026.0C,+024.8C,059.0%,000.00m/s,0,0000.0mm,0000.0mm
18:30:04,05/10/13,025.7C,+024.8C,058.7%,000.00m/s,0,0000.0mm,0000.0mm
18:30:04-> Time
05/10/13-> Date
025.7C -> Unit Temperature
+024.8C -> Atmosphere Temperature
058.7% -> Relative Humidity
Rest are Not useful
Can any one tell how to plot Temperature w.r.t time for each day on Separate graphs(Figure in MATLAB)
Please Help

채택된 답변

Walter Roberson
Walter Roberson 2013년 10월 7일
fid - fopen('YourFile.txt');
datacell = textscan(fid, '%s%s%fC%fC%f%*[^\n]', 'Delimiter', ',');
fclose(datacell);
fulldates = strcat(datacell{2}, {' '}, datacell{1});
datenumbers = datenum(fulldates, 'mm/dd/yy HH:MM:SS');
unittemps = datacell{3};
atmtemps = datacell{4};
relhums = datecell{5};
fig1 = figure();
ax1 = axes('Parent', fig1);
plot(datenumbers, unittemps, 'Parent', ax1);
datetick(ax1, 'x', 'HH:MM:SS');
title(ax1, 'Time vs Unit Temperature, Uni');
The refinement after this would be to split it down to individual days. For example as a quick hack:
datechars = char(datacell{2});
differentdates = any(diff(datchars, 1), 2);
Then differentdates will be true at location K if the K'th date differs from the (K+1)'th date and so indicates that you should split after the K'th row. Note that the result will be one element shorter than the number of row entries.

추가 답변 (1개)

Arun Sharma
Arun Sharma 2013년 10월 7일
편집: Walter Roberson 2013년 10월 7일
I had attached the file, and its not working
I found some errors like
fid = fopen('YourFile.txt');
datacell = textscan(fid, '%s%s%fC%fC%f%*[^\n]', 'Delimiter', ',');
fclose(fid);
I will try to use your code.
Can i use datetick function in MATLAB for solving my problem
  댓글 수: 3
Arun Sharma
Arun Sharma 2013년 10월 7일
Thanks Sir, Actually i solved my Problem using dataticks, i will see your method to,it also looks interesting.
Arun Sharma
Arun Sharma 2013년 10월 10일
Thank You So Much, I tried your method and it works. :-)
Here is the Code i wrote.
fid = fopen('LOGGER.CSV','r');
DataCell = textscan(fid,'%s %s %fC %fC %f%*[^\n]',1329,'Delimiter',',')
FullDate = strcat(DataCell{2},{' '},DataCell{1})
DateNumbers = datenum(FullDate,'mm/dd/yy HH:MM:SS')
UnitTemp = DataCell{3}
AtmTemp = DataCell{4}
Humidity = DataCell{5}
fig figure1
fig1 = figure();
ax1 = axes('Parent',fig1)
plot(DateNumbers,UnitTemp,'Parent',ax1);
grid on
axis([min(DateNumbers) max(DateNumbers) 20 30])
datetick(ax1,'x','HH:MM')
xlabel('Time\rightarrow');
ylabel('Temperature \rightarrow');
title('Temperature Graph 5th October');
fclose(fid);
Can You Explain me the meaning of this line
DataCell = textscan(fid,'%s %s %fC %fC %f%*[^\n]',1329,'Delimiter',',')
This part [^\n], although i know what it is doing but still wants to know this notation.
And Also the meaning of this line.
ax1 = axes('Parent',fig1)
Thank You Much, You method is perfect one.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by