How to find and replace the content of an array
1 次查看(过去 30 天)
显示 更早的评论
Hi guys. Sorry to bother you again, but I am new at Matlab.
I have this timestamp array:
'03/07/2019'
'03/07/2019 00:30:00'
'03/07/2019 01:00:00'
'03/07/2019 01:30:00'
'03/07/2019 02:00:00'
'03/07/2019 02:30:00'
And it goes for 10 days (480 values). The first cell of each day is like '03/07/2019', time is missing. I need to find this kind of cell
and add '00:00:00' to the cell content. So, the first cell should be '03/07/2019 00:00;00' instead of '03/07/2019'.
I applied the function cellfun. The length of the desirable cells is 10. I know I have to find the content of these cells and replace it,
but I am writing a loop. I wonder if there is an easier way to do that.
Thank you for your support!
0 个评论
采纳的回答
Mohammad Sami
2020-4-8
编辑:Mohammad Sami
2020-4-8
% sometimestamp = {'03/07/2019' '03/07/2019 00:30:00'};
l = cellfun(@length,sometimestamp);
% or
% l = strlength(sometimestamp);
sometimestamp(l==10) = cellfun(@(x)[x ' 00:00:00'],sometimestamp(l==10),'UniformOutput',false);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!