replace values in char array if conditions are met
Mostrar comentarios más antiguos
I have a datestr of 15 minute data from a certain location (minDNB):
ex) minDNB = '00','15','30','45','00','15',30','45' etc.
my goal is to replace each value or create a new matrix with fractions of an hour:
goal: newminDNB = 0.00, 0.25, 0.50, 0.75, 1.00, 1.25, 1.50, 1.75, 2.00, etc.
How should I go about this? I would like to loop through minDNB because some time stamps are missing and I need to retain gaps in the data. Thanks.
time00 = '00';
time25 = '15';
time50 = '30';
time75 = '45';
A = size(minDNB)
for i = 1:numel(minDNB)
if minDNB(i) == time00
A(i) = 0.00;
else if minDNB == time25
A(i) = 0.25 ;
else if minDNB(i) == time50
A(i) = 0.50 ;
else if minDNB(i) == time75
A(i) = 0.75 ;
end
end
end
end
end
Respuesta aceptada
Más respuestas (1)
C = {'00','15','30','45','00','15','30','45'};
V = str2double(C)/60;
V = V+cumsum([0,diff(V)<0])
3 comentarios
Given your uploaded data you should just use DURATION objects:
unzip('Riverstn.mat.zip')
S = load('Riverstn.mat')
H = str2double(cellstr(S.hourDNB));
M = str2double(cellstr(S.minDNB));
D = duration(H,M,zeros(numel(M),1))
Nicholas Modar
el 4 de Nov. de 2021
if you're just going through cellstrs to get from datetime to double, you can skip that step:
d=datetime(2010,1,1,10,30,00);
d.Hour
d.Minute
Categorías
Más información sobre Whos en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!