# How to add a matrix vertically and nest an if loop

1 vue (au cours des 30 derniers jours)
WILLBES BANDA le 31 Mar 2020
Commenté : WILLBES BANDA le 31 Mar 2020
Hi, i have a vector OxygenT = [0 5] and i want to add [0 5] to the next row so that i get 0 5
0 10
. .
. .
and i want it to continue until it equals the length of vector Oxygen below
Oxygen = 21.9599
22.6469
22.4288
19.0584
21.8578
24.4726
24.0144
19.7079
22.6187
24.2526
19.1982
23.0555
21.2375
19.7511
22.3351
20.9603
21.7795
19.3307
23.0599
Since i am dealing with time, how can i nest my loop such that when minutes(2nd column) reach 60 then 1 hour is added to column 1
Below is my code but when i run the code i only get 2 rows and it doesn`t add up until length of Oxygen. Please help
OxygenT = [0 5]
if length(OxygenT) <= length(Oxygen)
secondtime_interval = [OxygenT + OxygenT]
Oxygentime=[OxygenTime;secondtime_interval]
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Guillaume le 31 Mar 2020
Using a loop for this would be pointless and unnecessary complicated
Oxygenminute = (1:numel(Oxygen))' * 5;
Oxygenhour = floor(Oxygenminute/60);
Oxygenminute = mod(Oxygenminute, 60);
Oxygentime = [Oxygenhour, Oxygenminute]
An even better solution is to use a duration type instead of splitting the time over two columns:
Oxygentime = minutes(5) * (1:numel(Oxygen))';
Oxygentime.Format = 'hh:mm'
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
WILLBES BANDA le 31 Mar 2020
It works perfectly, thank you so so much honourable

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Logical dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by