how to read selected data from text file matlab ?
조회 수: 5 (최근 30일)
이전 댓글 표시
hi, I have this text file. (attached).
from this text file I only want read only second column(date), third column(time) and the last column. first 11 rows can be deleted. since time and date are two different column I am not able to combine them and make single vector. I just want do hourly average which I can do for sure. but I can not read and collect the data from this file in the first place. I Hope you understand my question. thanks
댓글 수: 0
채택된 답변
jonas
2018년 8월 16일
편집: jonas
2018년 8월 16일
readtable can do this for you easily.
%%Read the relevant columns, exclude 10 rows
opts=detectImportOptions('str.txt','NumHeaderLines',10);
opts.SelectedVariableNames = {'timestamp','RPM','absE_f'};
opts = setvartype(opts,{'timestamp','RPM'},{'datetime','duration'})
T=readtable('str.txt',opts)
t=T.timestamp+T.RPM;
readtable automatically detects the datetime and duration format of columns 2 and 3. If it fails, you can specify the format in detectImportOptions. Now, just build a timetable:
TT=timetable(t,T.absE_f)
ans =
10×1 timetable
t Var1
____________________ ________
02-Jan-2006 00:00:00 131.96
02-Jan-2006 00:00:10 -0.26753
02-Jan-2006 00:00:20 -0.29573
02-Jan-2006 00:00:30 127.73
Finally,
TT2 = retime(TT,'hourly','mean')
댓글 수: 16
jonas
2018년 8월 17일
Yes sorry, my bad. Grab the time by
datenum(TT.t)
No problem! Happy to help.
참고 항목
카테고리
Help Center 및 File Exchange에서 Timetables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!