0

I want to get Nx1 cell array from 1x1 cell array of datetime string. Where N is greater than 98.

Time = {datestr(now(),'mmmm dd, yyyy HH:MM:SS.FFF')};

Time =

  1×1 cell array

    {'January 28, 2021 12:27:15.280'}

I want to convert this as

    Time=  
    5×1 cell array
    
        {'January 28, 2021 17:24:47.119'}
        {'January 28, 2021 17:24:47.119'}
        {'January 28, 2021 17:24:47.119'}
        {'January 28, 2021 17:24:47.119'}
        {'January 28, 2021 17:24:47.119'}

I am doing this using

Time=[Time;Time;Time;Time;Time]

But for variable and large value of N, it is very difficult.

1
  • Just for information, you might find using datetime arrays more flexible than cell arrays of strings. For more information on handling dates and times in MATLAB using datetime, see mathworks.com/help/matlab/… Commented Jan 28, 2021 at 16:31

1 Answer 1

2

Use repmat:

Time = {datestr(now(),'mmmm dd, yyyy HH:MM:SS.FFF')};
Nrows = 100;
Ncols = 1;
Time = repmat(Time, [Nrows, Ncols]);
Sign up to request clarification or add additional context in comments.

1 Comment

Solved my problem. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.