Error using dtstr2dtvecmx Failed on converting date string to date number. Error in datevec (line 117) y = dtstr2dtve​cmx(t,icu_​dtformat);

Here is the script:
clear all; close all
clc
%%%% Directories
direc1 = '/Users/Degausseridae/Documents/Research/EggLoggerData/sas_00_createmetadata_Needs/';
direc2 = '/Users/Degausseridae/Documents/Research/EggLoggerData/sas_00_createmetadata_Produces/';
%%%% File to be read in
file2Load = 'BNSTdata.csv';
formatSpec1 = '%s %u %u %s %s %u %u %u %s %u %s %s %s %s %s %s %s %s %f %f %f %s %s %s %u %s';
formatIn = 'mm/dd/yyyy';
N = 26;
%%%% Import file
fileID = fopen([direc1,file2Load]);
C_data = textscan(fileID,formatSpec1,N,'Headerlines',1,'Delimiter',',');
fclose(fileID);
%%%% logger start date
sDate = datevec(C_data{1,13},formatIn);
Here is the error:
Error using dtstr2dtvecmx Failed on converting date string to date number.
Error in datevec (line 117) y = dtstr2dtvecmx(t,icu_dtformat);
Error in sas_00_createmetadata_GT (line 42)
sDate = datevec(C_data{1,13},formatIn);
I've attached the csv file I'm using

Réponses (1)

I was able to replicate the issue and encountered the same error.
The error arises because ‘C_data{1,13}’ contains some empty character cells ({0x0 char}). This is likely due to an incorrect import process.
Removing these empty character cells from ‘C_data{1,13}’ resolved the error.
d = C_data{1,13};
emptyIndex = cellfun(@isempty, d); % The ‘cellfun’ function is used to apply the ‘isempty’ function
% to each element in ‘d’, identifying the indices of the empty character cells.
C_filtered = d(~emptyIndex);
sDate = datevec(C_filtered,formatIn); % works fine
If you like to explore more about ‘cellfun’, you can refer to its documentation page by executing the following command in the MATLAB Command Window:
doc cellfun
Hope this helps!

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by