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 ExchangeData 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