Plotting Temperature with respect to time in MATLAB from a file??
6 views (last 30 days)
Show older comments
Arun Sharma
on 7 Oct 2013
Commented: Arun Sharma
on 10 Oct 2013
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
0 Comments
Accepted Answer
Walter Roberson
on 7 Oct 2013
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.
0 Comments
More Answers (1)
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!