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!

 采纳的回答

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

Community Treasure Hunt

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

Start Hunting!

Translated by