Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

How to convert 1x1 cell array to 5x1 cell array of datetime string in Matlab

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.

question from:https://stackoverflow.com/questions/65936852/how-to-convert-1x1-cell-array-to-5x1-cell-array-of-datetime-string-in-matlab

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use repmat:

Time = {datestr(now(),'mmmm dd, yyyy HH:MM:SS.FFF')};
Nrows = 100;
Ncols = 1;
Time = repmat(Time, [Nrows, Ncols]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...