How improve for cycle with sequential variables name and time evaluate ?
Mostrar comentarios más antiguos
I've this for 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
I want to assign a cumulative name at the variables 'out' like 'out-1', 'out-2', ... for each for cycle. I try do that with this code:
t1 = cell(numel(D), 1);
t2 = cell(numel(D), 1);
for j=1:numel(D);
t1{j} = sprintf('TimeStart %u', j);
t2{j} = sprintf('TimeFinish %u',j);
end
But I don't now how put this code in the for cycle.
I need to evaluate che difference between two dates & times, and for do that I use this code:
prova = [out{1,1}, ' ', out{1,2}];
prova2 = [out{2,1}, ' ', out{2,2}];
format shortg;
t1 = datevec(prova,'yyyy/mm/dd HH:MM');
t2 = datevec(prova2,'yyyy/mm/dd HH:MM');
e=etime(t2, t1)
I need to do that with a iterative cycle, for each cell and create a file with the column of results.
Thanks in advance.
Stefano
1 comentario
Stephen23
el 11 de Feb. de 2016
Read the answers, and then use a cell array or structure.
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 11 de Feb. de 2016
0 votos
2 comentarios
Stefano Alberti
el 11 de Feb. de 2016
Walter Roberson
el 11 de Feb. de 2016
Editada: Stephen23
el 11 de Feb. de 2016
"I want to assign a cumulative name at the variables 'out' like 'out-1', 'out-2'"
Don't do that. Indices have no place in variable names. If you want to index, use a cell array or struct array.
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!