How convert cell array inside a cell array in a string with date and time format ?

I've use this code to take a string like this: Daily_cum_2013_05_30_09_59__2013_05_31_10_05.asc and split it in two columns with only the numeric format (this a date and time).
sC = regexp(F, 'Daily_cum_', 'split');
sC = vertcat(sC{:});
sC(:, 1) = [];
sC = regexp(sC, '\.asc', 'split');
sC = vertcat(sC{:});
sC = regexp(sC, '__', 'split');
sC = sC(:,1);
Now I've a cells (4000x1) with inside a another cells (1x2).
How I can split this cells inside a string e convert to data and time format ?
Thanks
Stefano

 Akzeptierte Antwort

F='Daily_cum_2013_05_30_09_59__2013_05_31_10_05__2013_05_31_10_08'
a=F(11:end)
b=regexp(a,'__','split')
out1=cellfun(@(x) datestr(datenum(x(1:10),'yyyy_mm_dd'),'yyyy/mm/dd'),b,'un',0)
out2=cellfun(@(x) datestr(datenum(x(12:end),'HH_MM'),'HH:MM'),b,'un',0)
out=[out1' out2']

4 Kommentare

Thank oyu very much Azzi.
My input data is like the precedent code (Daily_cum_ecc) but is stored in a 4000x2 cell. How can resolve that ?
Thanks
F='Daily_cum_2013_05_30_09_59__2013_05_31_10_05__2013_05_31_10_08'
a=F(11:end)
b=regexp(a,'__','split')
out=[cellfun(@(x) x(1:10),b,'un',0)' cellfun(@(x) x(12:end),b,'un',0)']
Thanks but I've stored data like this :
val =
Daily_cum_2013_05_30_09_59__2013_05_31_10_05.asc
Daily_cum_2013_05_30_10_55__2013_05_31_11_01.asc
Daily_cum_2013_05_30_11_32__2013_05_31_11_38.asc
Daily_cum_2013_05_30_12_09__2013_05_31_12_15.asc
Daily_cum_2013_05_30_12_46__2013_05_31_12_52.asc
Daily_cum_2013_05_30_13_23__2013_05_31_13_30.asc
Daily_cum_2013_05_30_14_00__2013_05_31_14_08.asc
...
Ok, I resolved with this cycle:
for k =1:3 %numel(D)
fid = fopen(fullfile(D(k).name), 'rt');
filename = D(k).name ;
a=filename(11:end);
b=regexp(a,'__','split');
out1=cellfun(@(x) datestr(datenum(x(1:10),'yyyy_mm_dd'),'yyyy/mm/dd'),b,'un',0);
out2=cellfun(@(x) datestr(datenum(x(12:end),'HH_MM'),'HH:MM'),b,'un',0);
out=[out1' out2'];
clearvars out1 out2;
fclose(fid);
end
but now, how to give a sequential name for each value and how to create a cell with in a row data1 time1 and data2 time2, beloew it data1-1 timne1-1 and data2-1 time2-1 ...
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by