How to split numeric values and store them?
Mostra commenti meno recenti
I have the array below with activities 1, 2 and 3 and the times the system has spent in these activities. Not every row is a new date. For example, the first value (24) is 1/1/2015, however, the two following values (22.3 + 1.7 = 24) is on 1/2/2015, and so on.
Modes2 =
0 0 24.0000
0 0 22.3000
0 0 1.7000
0 0 13.0000
0 11.0000 0
0 24.0000 0
0 24.0000 0
0 24.0000 0
0 24.0000 0
0 17.2833 0
0 3.7667 0
2.9500 0 0
7.1167 0 0
16.8833 0 0
24.0000 0 0
To further analyse these, the need to be stored per 6 hours in something like the following.
Time_periods1 =
1/1/2015 6 hr 0 0 0
1/1/2015 12 hr 0 0 0
1/1/2015 18 hr 0 0 0
1/1/2015 24 hr 0 0 0
1/2/2015 6 hr 0 0 0
1/2/2015 12 hr 0 0 0
1/2/2015 18 hr 0 0 0
1/2/2015 24 hr 0 0 0
1/3/2015 6 hr 0 0 0
1/3/2015 12 hr 0 0 0
1/3/2015 18 hr 0 0 0
1/3/2015 24 hr 0 0 0
1/4/2015 6 hr 0 0 0
1/4/2015 12 hr 0 0 0
I wrote the following, does not work, now I'm lost.
for i=1:size(Modes2,1)
for j=1:size(Time_periods2,1)
for k=1:7
if (Modes2(i,k)>0 && Modes2(i,k)<=6)
Time_periods2(j,k)=Modes2(i,k);
elseif (Modes2(i,k)>6 && Modes2(i,k)<=12)
Time_periods2(j+1,k)=Modes2(i,k)-6;
Time_periods2(j,k)=6;
elseif (Modes2(i,k)>12 && Modes2(i,k)<=18)
Time_periods2(j+2,k)=Modes2(i,k)-12;
Time_periods2(j+1,k)=6;
Time_periods2(j,k)=6;I
elseif (Modes2(i,k)>18 && Modes2(i,k)<=24)
Time_periods2(j+3,k)=Modes2(i,k)-18;
Time_periods2(j+2,k)=6;
Time_periods2(j+1,k)=6;
Time_periods2(j,k)=6;
end
end
end
end
Any ideas?
3 Commenti
Showing the expected output helps us much more than showing non-functioning code.
Please show the complete expected output for the sample data you have given.
Note that not everyone on this forum is from the USA, and readers might interpret "1/2/2015" as the 1st of February 2015. Using ISO 8601 dates is unambiguous.
Rik
il 19 Nov 2019
It looks like the brunt of your code is trying to determine when 24 hours have passed. To find the sequential day, you could also use the line of code below.
day_ID=ceil(cumsum(sum(Modes2,2))/24);
If you use that to generate the first column, wouldn't that be fairly close to what you mean?
Ymkje Lize Neuteboom
il 19 Nov 2019
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Historical Contests in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!