plot date from excel file

hi all, I am trying to plot power vs time in my program, these values are taking from excel file, but I am having different values for the time compare with values in excel, the time format is (HH:MM)and my code is:
[num,T,vT] = xlsread(excle.xls,'Sheet1'); % reading excel
x = num(:,1); % Time column
y = num(:,4); % power column
plot(handles.axes,x,y);
how can I over come this issue ??? please help and advice...

댓글 수: 3

Conrad
Conrad 2012년 7월 26일
Can you give a concrete example of what the time looks like in Excel and then in Matlab?
Sumit Tandon
Sumit Tandon 2012년 7월 26일
Not sure if I understand the question correctly. Are you having issues with the FORMAT of date in Excel vs MATLAB? You could use functions like DATENUM or DATEVEC to change the format and then plot as per your requirements.
Samer Husam
Samer Husam 2012년 7월 26일
conrad: the time value is read from MATLAB it something like: 12:00, 12:15, 12:30 and so on. when I use the code that I post above, I get numeric values like 0.5, 0.51... so how can I display the time values from the excel ??
LukeS: I have tried to use the datenum but what I couldn't get it correctly, can you please show me how to use it ?

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

답변 (2개)

Thomas
Thomas 2012년 7월 26일

0 개 추천

Something like this
x={'12:00','12:15','12:30','12:45'}; %time
y=[0.5 0.8 0.3 0.6] % values
time_out=datenum(x,'HH:MM'); %convert time to datenum
plot(time_out,y)
datetick('x','HH:MM') % show datetick on xaxis

댓글 수: 5

the values of x and y is not in array, so when i am using your answer i am getting an error, this what I am doing:
[num,T,vT] = xlsread(excle.xls,'Sheet1'); % reading excel
x = num(:,1); % Time column
y = num(:,4); % power column
x1= datenum(x,'HH:MM'); %convert time to datenum
plot(x1,y)
but I am getting an error.. so how can I over come this??? and thanks for your answer
Thomas
Thomas 2012년 7월 26일
what error are you getting and can you show how x is in MATLAB?
Samer Husam
Samer Husam 2012년 7월 26일
the error i am getting is:
The input to DATENUM was not an array of strings.
so what is your 'x'? Can you show an example of 'x' as it is imported in matlab. also what is the output of
whos x
Samer Husam
Samer Husam 2012년 7월 26일
편집: Samer Husam 2012년 7월 26일
x is the time values to be read from excel (ex: 12:00 and 12:15)
y is the power values also to be read from excel.

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

Samer Husam
Samer Husam 2012년 7월 28일

0 개 추천

is it possible to use datetick function is this ?? please help...

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

질문:

2012년 7월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by