Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:51:09+00:00 2026-05-27T23:51:09+00:00

In my code I have looped different text files to get the time elapsed

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:51:10+00:00Added an answer on May 27, 2026 at 11:51 pm

    datenum did not fail to me when receiving values for hour greater than 24. For example:

    >> time = '06.12.2011 53:31:11';
    >> timen=datenum(time,'dd.mm.yyyy HH:MM:SS');
    >> datestr(timen,'dd.mm.yyyy HH:MM:SS')
    
    ans =
    
    08.12.2011 05:31:11
    

    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:

    time=cellfun(@(x) sprintf('%s %s',day{strcmpi(hour,x)},x),hour,'uniformoutput',0);
    

    will concatenate multiple values of day and one value of hour generating an invalid time string such as '07.12.2011 07.12.201110:36:11 '

    Since it looks like you want one value of time per observation (as opposed to one per unique(hour)), I suggest calculating time as

    time = strcat(day,{' '},hour)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked at the generated designer code of Form s and UserControl s,
Put it another way: what code have you written that cannot fail. I'm interested
We’ve found that the unit tests we’ve written for our C#/C++ code have really
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =
I have code that references a web service, and I'd like the address of
I have code to create another row (div with inputs) on a button click.
I have code similar to this filtering entries in an Array of Objects: var
I have code like this: var newMsg = new Msg { Var1 = var1,
I have code like this: template <typename T, typename U> struct MyStruct { T
I have code similar to the following in many places: var dbParams = db.ReadParams(memberID,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.