Reading the exact time and date as in excel sheet !

18 ビュー (過去 30 日間)
chamant swarup
chamant swarup 2019 年 1 月 22 日
コメント済み: Peter Perkins 2019 年 1 月 24 日
Time that is being displayed in workspace editor !!
Original time stamp !!
[Houseload,text,rawdata] = xlsread('Haushalt-Lastprofil.xls','Profil');
time = Houseload (:,1);
what is the next code line to be implemented ! here are few things i implemented based on few examples discussed in the forum but was not sucessful .
1) timecolomn = datestr(datenum(time(:,1)), 'hh:mm');
2) datestr(Houseload,'mm/dd/yyyy hh:mm:ss')
I would also like to know the code to read if the following format it existed !
01.01.2017 01:15:00
thanks !
  5 件のコメント
chamant swarup
chamant swarup 2019 年 1 月 22 日
Please find the attached excel file asked for !!
Thanks !



per isakson
per isakson 2019 年 1 月 23 日
編集済み: per isakson 2019 年 1 月 23 日
"based on few examples discussed in the forum" The Matlab documentation is a much more reliable when it comes to the behavior of specific functions. Yes, you want to use the function datestr(). Thus see datestr, Convert date and time to string format and notice that
Symbolic Identifier Description
HH Hour in two digits
MM Minute in two digits
That is capital letters "H" and "M". Run this code
[Houseload,text,rawdata] = xlsread('Haushalt-Lastprofil.xls','Profil');
time = Houseload (:,1);
datestr( time, 'HH:MM' )
ans =
96×5 char array
I use R2018b. However, datestr() was Introduced before R2006a and should work with R2007. Possibly, your output will include default values for year, month and day.
"I would also like to know [...]" It does and the answer is in the documentation datestr()
  2 件のコメント
per isakson
per isakson 2019 年 1 月 24 日
With R2018b I get
Error using plot
Invalid first data argument.
Error in Untitled (line 6)
I see two problems with your code:
  1. the use of ans, Most recent answer in a script/function. That is asking for trouble. (It is used in Cody to trick the size calculator, by avoiding creation of one variable.)
  2. the value of ans in your case is a character array. That makes plot() throw an error.
plot( Hloadprofile(:,1), TotconYEAR );


その他の回答 (1 件)

Peter Perkins
Peter Perkins 2019 年 1 月 23 日
chamant, you will be much better off using readtable, and durations, if you have anythign like a recent version of MATLAB.
  3 件のコメント
Peter Perkins
Peter Perkins 2019 年 1 月 24 日
readtable has had a lot of functionality added over the last couple years, so check the documentation for the version you are running. Notably, recent versions of readtable work with detectimportoptions. If you have a recent enough version of MATLAB, that's the way to go. If not, still I would recommend readtable, and if the dates come in as strings, convert them to datetime.





Community Treasure Hunt

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

Start Hunting!

Translated by