Filter löschen
Filter löschen

how to make datetime data readable and convert to julian date?

1 Ansicht (letzte 30 Tage)
greeting sir, I want to convert date time with YYYY/MM/DD HH:MM:SS format in my file to julian date. When I load my data, the datenumber changed to NaN
This is what I've tried
clc;clear; close all;
% Specify the folder where the files live.
myFolder = 'C:\ZTD\CSV';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
Allfile = fullfile(myFolder, '*.txt'); % Change to whatever pattern you need.
List = dir(Allfile);
for k = 1 : length(List)
sites = List(k).name;
num = readmatrix(sites,"NumHeaderLines",1);
num(:,end)=[];
time = num(1:end,1);
% % julian date corresponding to 2000-01-01 00:00:00.0
mjd20000 = 51544;
How to make my date time data readable and calculate it to julian date?

Akzeptierte Antwort

VBBV
VBBV am 28 Dez. 2022
use readtable instead of readmatrix
D = readtable('dd.txt') % use readtable
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
D = 4259×19 table
Date_Asia_Jakarta_ Tempin__C_ Temp__C_ Chill__C_ Dewin__C_ Dew__C_ Heatin__C_ Heat__C_ Humin___ Hum___ Wspdhi_m_s_ Wspdavg_m_s_ Wdiravg___ Bar_hPa_ Rain_mm_ Et_mm_ Rainrate_mm_h_ Solarrad_W_m__ Uvi__ __________________ __________ ________ _________ _________ _______ __________ ________ ________ ______ ___________ ____________ __________ ____________ ________ ______ ______________ ______________ _____ 01/01/2022 00:00 27.3 25.3 25.3 NaN 23.3 NaN 25.3 52 89 1.5 1.1 229 {'1,010.90'} 0 NaN 0 0 0 01/01/2022 00:10 27.3 25.1 25.1 NaN 23.3 NaN 25.1 52 90 0 0 226 {'1,010.80'} 0 NaN 0 0 0 01/01/2022 00:20 27.3 25 25 NaN 23.2 NaN 25 52 90 0 0 226 {'1,010.40'} 0 NaN 0 0 0 01/01/2022 00:30 27.3 24.9 24.9 NaN 23.4 NaN 24.9 52 91 0 0 226 {'1,010.20'} 0 NaN 0 0 0 01/01/2022 00:40 27.3 24.9 24.9 NaN 23.4 NaN 24.9 52 91 0 0 226 {'1,010.30'} 0 NaN 0 0 0 01/01/2022 00:50 27.2 24.8 24.8 NaN 23.3 NaN 24.8 52 91 0.5 0.4 226 {'1,010.20'} 0 NaN 0 0 0 01/01/2022 01:00 27.1 24.8 24.8 NaN 23.3 NaN 24.8 52 91 0 0 226 {'1,010.10'} 0 NaN 0 0 0 01/01/2022 01:10 27.2 24.8 24.8 NaN 23.5 NaN 24.8 52 92 0 0 226 {'1,010.20'} 0 NaN 0 0 0 01/01/2022 01:20 27.2 24.8 24.8 NaN 23.3 NaN 24.8 52 91 0 0 226 {'1,010.10'} 0 NaN 0 0 0 01/01/2022 01:40 27.1 24.8 24.8 NaN 23.5 NaN 24.8 52 92 0 0 226 {'1,010' } 0 NaN 0 0 0 01/01/2022 01:50 27.1 24.8 24.8 NaN 23.3 NaN 24.8 52 91 0.5 0.1 226 {'1,009.80'} 0 NaN 0 0 0 01/01/2022 02:00 27.1 24.8 24.8 NaN 23.3 NaN 24.8 52 91 0 0 226 {'1,009.80'} 0 NaN 0 0 0 01/01/2022 02:10 27.1 24.8 24.8 NaN 23.3 NaN 24.8 52 91 0.5 0.5 226 {'1,009.80'} 0 NaN 0 0 0 01/01/2022 02:20 27.1 24.7 24.7 NaN 23.2 NaN 24.7 52 91 0.5 0.5 225 {'1,009.80'} 0 NaN 0 0 0 01/01/2022 02:30 27 24.7 24.7 NaN 23.2 NaN 24.7 52 91 0.5 0.2 226 {'1,009.80'} 0 NaN 0 0 0 01/01/2022 02:40 27 24.6 24.6 NaN 23.1 NaN 24.6 52 91 0 0 226 {'1,009.90'} 0 NaN 0 0 0
dt = D.Date_Asia_Jakarta_
dt = 4259×1 datetime array
01/01/2022 00:00 01/01/2022 00:10 01/01/2022 00:20 01/01/2022 00:30 01/01/2022 00:40 01/01/2022 00:50 01/01/2022 01:00 01/01/2022 01:10 01/01/2022 01:20 01/01/2022 01:40 01/01/2022 01:50 01/01/2022 02:00 01/01/2022 02:10 01/01/2022 02:20 01/01/2022 02:30 01/01/2022 02:40 01/01/2022 02:50 01/01/2022 03:00 01/01/2022 03:10 01/01/2022 03:20 01/01/2022 03:30 01/01/2022 03:40 01/01/2022 03:50 01/01/2022 04:00 01/01/2022 04:10 01/01/2022 04:20 01/01/2022 04:30 01/01/2022 04:40 01/01/2022 04:50 01/01/2022 05:00
jd = juliandate(dt)
jd = 4259×1
1.0e+06 * 2.4596 2.4596 2.4596 2.4596 2.4596 2.4596 2.4596 2.4596 2.4596 2.4596
  4 Kommentare
adhi dermawan
adhi dermawan am 28 Dez. 2022
I got another error sir
Error using mjuliandate (line 94)
Input must be an M-by-6 or M-by-3 matrix containing M full or partial date vectors, a date string and the format for the
date string, or three or six separate numeric arrays of the same size.
Error in csvcoba (line 29)
mjd = mjuliandate(jd);
adhi dermawan
adhi dermawan am 28 Dez. 2022
I solved it in another way. thank you for helping me sir

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by