Reading the exact time and date as in excel sheet !

조회 수: 11 (최근 30일)
chamant swarup
chamant swarup 2019년 1월 22일
댓글: Peter Perkins 2019년 1월 24일
Time that is being displayed in workspace editor !!
0,0104166666666667
0,0208333333333333
0,0312500000000000
0,0416666666666667
0,052083333333333
Original time stamp !!
0:15
0:30
0:45
1:00
1:15
[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
madhan ravi
madhan ravi 2019년 1월 22일
편집: madhan ravi 2019년 1월 22일
In that case you should upload your original excel file to experiment so that others can give you a precise result , next time when you ask a question make sure you fill "Products" and "Release" field so that this type of confusions can be avoided.
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' )
outputs
ans =
96×5 char array
'00:15'
'00:30'
'00:45'
'01:00'
'01:15'
'01:30'
...
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
chamant swarup
chamant swarup 2019년 1월 23일
편집: chamant swarup 2019년 1월 23일
Thanks for the help !! even i switched to the latest version today !
Now to plot the time versus the data i am looking for ,
why the following doesnt work? it says
Error in loadprofiles (line 6)
plot(ans,TotconYEAR);
pls find the excel file if needed below
[ Hloadprofile,text,raw ] = xlsread('Householdload.xls','Profil');
% time = Hloadprofile(:,1);
datestr( Hloadprofile ,'HH:MM');
TotconYEAR = Hloadprofile(:,11);
plot(ans,TotconYEAR);
per isakson
per isakson 2019년 1월 24일
With R2018b I get
Error using plot
Invalid first data argument.
Error in Untitled (line 6)
plot(ans,TotconYEAR);
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.
Try
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
per isakson
per isakson 2019년 1월 24일
Yes, but don't forget
T = readtable( _____, 'DatetimeType', 'exceldatenum' )
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2007b

Community Treasure Hunt

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

Start Hunting!

Translated by