How do I split a data set into multiple chunks based on a re-occuring value?

Hello all, I have an N x 2 matrix of temperature data vs time. In my first column, a value of -99999 (column 1) represents a time value (column 2), and the preceeding column 1 values after the -99999 are element numbers, while the preceeding column 2 values after the time are temperatures. Everytime there is a new time value, the column 1 value for that time will be -99999 (see .txt file). I would like to read in my .txt file, split the data into temperature vs element, vs time, and then use this data so that I can view one singular element of choice's temperature data vs time. I have attached my .txt data file so that you can see what I am working with. Thank you so much in advance!

 채택된 답변

dpb
dpb 2022년 8월 19일
편집: dpb 2022년 8월 20일
data=readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1102540/Temps.txt');
iT=(data(:,1)==-99999);
nVals=diff(find(iT));
assert(all(nVals==nVals(1)),'Unequal Number Elements In Groups')
dT=find(iT);
nVals=nVals(1)-1;
Time=seconds(repelem(data(iT,2),nVals));
ttD=timetable(Time,data(~iT,1),data(~iT,2),'VariableNames',{'Element','Temperature'});
head(ttD,5)
ans = 5×2 timetable
Time Element Temperature _____ _______ ___________ 0 sec 1 -55 0 sec 2 -55 0 sec 10 -55 0 sec 11 -55 0 sec 12 -55
Use the Element variable as selection or grouping variable to compute whatever by one or group of elements.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Acquisition Toolbox Supported Hardware에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 8월 19일

편집:

dpb
2022년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by