How to find and replace the content of an array

조회 수: 1 (최근 30일)
JOAO LIMA
JOAO LIMA 2020년 4월 8일
댓글: JOAO LIMA 2020년 4월 9일
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!

채택된 답변

Mohammad Sami
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);
  댓글 수: 1
JOAO LIMA
JOAO LIMA 2020년 4월 9일
Mohammad Sami , I implemented all the suggestions. ! You guys are great!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Bhaskar R
Bhaskar R 2020년 4월 8일
out = cellfun(@(x)datetime(x, 'Format','dd/MM/yyyy HH:mm:ss'), input_cell)

Stephen23
Stephen23 2020년 4월 8일
>> C = {'03/07/2019' '03/07/2019 00:30:00'};
>> X = cellfun('length',C)==10;
>> C(X) = strcat(C(X),' 00:00:00')
C =
03/07/2019 00:00:00
03/07/2019 00:30:00

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by