how to split table with different time values
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have an attached table with time column (hh:mm:ss) and a data column. I'd like to make separate columns or tables according to the different time (minutes) and plot seperate figures for that.
I attached the ''csv'' file here. Can someone help me, pls?
a = readtable('tb.csv')
2 commentaires
Réponse acceptée
Dyuman Joshi
le 2 Nov 2022
Modifié(e) : Dyuman Joshi
le 2 Nov 2022
Finding the indices where the minute starts/changes/ends -
a = readtable('tb.csv');
[~,~,~,h,m,~]=datevec(a.time);
y=unique([1 find(diff(m)~=0)'+1 numel(m)+1])
You can convert the data in different individual elements like this -
z=mat2cell(a.Var1,diff(y),1)
%you can plot directly as well
for i=1:numel(y)-1
figure
arr=y(i):y(i+1)-1;
plot(a.time(arr),a.Var1(arr),'color', rand(1,3))
end
5 commentaires
Plus de réponses (1)
Lei Hou
le 18 Nov 2022
Hi,
Datevec is in discourage use now. You can use retime to group your data and do plot.
>> tt = readtimetable('tb.csv')
tt =
675×1 timetable
time Var1
________ _______
14:46:13 -27.426
14:46:13 -12.221
14:46:13 15.665
14:46:13 -27.113
14:46:13 -12.416
: :
15:58:02 2.4096
15:58:02 12.741
15:58:02 7.5679
15:58:02 11.63
15:58:02 6.6887
Display all 675 rows.
>> tt1 = retime(tt,"minutely",@(x){x})
tt1 =
73×1 timetable
time Var1
________ ______________
14:46:00 {149×1 double}
14:47:00 { 0×1 double}
14:48:00 { 0×1 double}
14:49:00 { 0×1 double}
14:50:00 { 0×1 double}
: :
15:54:00 { 0×1 double}
15:55:00 { 0×1 double}
15:56:00 { 0×1 double}
15:57:00 {132×1 double}
15:58:00 { 18×1 double}
Display all 73 rows.
>> tt2 = tt1(cellfun(@(x)~isequal(x,double.empty(0,1)),tt1.Var1),:)
tt2 =
7×1 timetable
time Var1
________ ______________
14:46:00 {149×1 double}
15:02:00 { 86×1 double}
15:27:00 {161×1 double}
15:35:00 {106×1 double}
15:48:00 { 23×1 double}
15:57:00 {132×1 double}
15:58:00 { 18×1 double}
Voir également
Catégories
En savoir plus sur Timetables dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!