Convert time to datenum

조회 수: 2 (최근 30일)
Daniel Boateng
Daniel Boateng 2019년 3월 25일
댓글: Guillaume 2019년 3월 25일
I have a folder with 10 matfiles where the first row is the time and the second raw is some data associated with the time. I want to convert all the time for the first row of each of the matfiles as a new time series using datenum. I have been able to navigate to the directory of and tried this code but it isnt working. Please is can I get some help.
mat = dir('*.mat');
for i = 1:length(mat)
load(mat(i).name);
newMat = mat(i).name(1,:);
newdate = datenum(newMat);
end
  댓글 수: 1
Guillaume
Guillaume 2019년 3월 25일
Why not use datetime instead of datenum? It's more flexible and more reliable.

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

채택된 답변

Stephen23
Stephen23 2019년 3월 25일
편집: Stephen23 2019년 3월 25일
It is not required to navigate to data directories to read data:
D = 'Path of the directory where the MAT files are saved';
S = dir(fullfile(D,'*.mat'));
for k = 1:numel(mat)
T = load(fullfile(D,S(k).name));
M = T.nameOfTheVariableInMatFileWhichYouHaveNotToldUs;
newdate = datenum(M(1,:));
end
Or, assuming that the .mat files contain only one variable:
D = 'Path of the directory where the MAT files are saved';
S = dir(fullfile(D,'*.mat'));
for k = 1:numel(mat)
T = load(fullfile(D,S(k).name));
C = struct2cell(T);
newdate = datenum(C{1}(1,:));
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by