how to plot a time on x-axis and height on y-axis and data with respect to time
2 views (last 30 days)
Show older comments
i have a file that is having headerfile data headerfile data.............. in headerfile there is data ht u v w....... i want header seprate and i want to show the plot time(same time which is in text file)on x-axis which is in the headerfile and data u,v,z with respect to height on y-axis. i tried many times ,but time is passing no progress.could any one help me i want to show data is chaning with respect to time please give me program
2 Comments
Accepted Answer
dpb
on 30 Apr 2014
Edited: dpb
on 1 May 2014
...the date and time is in the header...
Oh, ok...I'm not sure you said that the first go 'round. So, modify the previous to handle that
c=[]; % an empty array to collect data into
dn=[]; % ditto for date/time as Matlab datenum
fmt=repmat('%f',1,4); % format string for the numeric data 4/record
fid=fopen('31oct97.txt','r'); % open the file, return file handle
while ~feof(fid) % begin loop until run out of data in file
l=fgetl(fid); % skip that first line
ERRATA: An extra '%' before the \n in both format strings in original...fixed.
dmy=fscanf(fid,'Date : %2d/%2d/%2d\n').'; % get the d,m,y values
dmy(3)=dmy(3)+1900; % fixup the 2-digit year, put in y,m,d order
hms=fscanf(fid,'Time: %2d:%2d:%2d\n').'; % and h,m,s
dn=[dn;datenum([fliplr(dmy) hms])]; % convert to datenum
% now read a remaining data chunk/concatenate-resize header lines to skip
c=[c;cell2mat(textscan(fid,fmt,187,'headerlines',21))];
fgetl(fid);fgetl(fid); % and get the \n and blank line to repeat
end
I actually debugged the above on your file with the only difference being for brevity I just kept two sets of headers and five lines of data/set. The one difficulty you may run into is that I now see that the data are duplicated for each time at positions I guess(?) so instead of concatenating c as above you may prefer to keep each iteration as a plane in a 3D array to keep each directly associated with the group. Otherwise I guess you'd end up wanting to select into rows by the number/group.
To plot the time series, having dealt with that one way or another,
plot(dn,c(suitable_indices))
datetick('x')
See
doc datenum % and friends
doc datetick
for more details on display time axes.
4 Comments
dpb
on 1 May 2014
...how to plot a raw file (.r1)files into timeseries...
No klew...where's there a definition of the file format?
I'd suggest this might be a case for
doc memmapfile
however
More Answers (0)
See Also
Categories
Find more on Dates and Time 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!