In my code I have looped different text files to get the time elapsed and the temperature. And then plot temperature and time
The text file has data like this
Date; Time; Temp °C
06.12.2011; 10:35:11;-24.13
06.12.2011; 10:36:34;-24.00
06.12.2011; 10:37:56;-23.88
.
.
.
.
header=fgetl(fid);
data=textscan(fid,'%s','delimiter',';');
fclose(fid);
data=data{:};
day=data(1:3:end);
hour=data(2:3:end);
temp=str2double(data(3:3:end));
time=cellfun(@(x) sprintf('%s %s',day{strcmpi(hour,x)},x),hour,'uniformoutput',0);
timen=datenum(time,'dd.mm.yyyy HH:MM:SS');
seconds=timen*86400/60;
plot(seconds-seconds(1),temp);
xlabel('Time(mins)');
ylabel('Temp °C');
But now when the time elapsed is greater than 24 hrs in the text files(the temperature reading last for more than one day), the datenum gives an error
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.
Any suggestions why this is happening, I tried using the same in command line it works fine there
datenumdid not fail to me when receiving values for hour greater than 24. For example:However, while trying to run your code, I did get the same error but in the cases when there were two observations with the same time stamp. That happens because the line:
will concatenate multiple values of
dayand one value ofhourgenerating an invalid time string such as'07.12.2011 07.12.201110:36:11 'Since it looks like you want one value of
timeper observation (as opposed to one perunique(hour)), I suggest calculatingtimeas