필터 지우기
필터 지우기

Put datetime scale in x-axis

조회 수: 1 (최근 30일)
rpid
rpid 2019년 1월 29일
댓글: Star Strider 2020년 12월 23일
Hey there. I need to to put datetime scale in x-axis. I attached the values in a xls file.
m3=[x1,x2,x3,x4];
startDate = datenum('10-2006');
endDate = datenum('11-2099');
xdate = linspace(startDate,endDate,373); %number of months
figure
bar(xdate,m3);
dateaxis('x','mm-yyyy','keeplimlits');
legend({'X1','X2','X3','X4'},'Location','Southeast');
Till now, I only got to put the datenum and only x1 appears. When I execute the code below, it runs (exception to datetime scale).
m3=[x1,x2,x3,x4];
figure
bar(m3);
legend({'X1','X2','X3','X4'},'Location','Southeast');
Is it possible to solve it? Thanks :-)

채택된 답변

Star Strider
Star Strider 2019년 1월 29일
The amount of data obscures all detail, however this works:
[D,S] = xlsread('matlab.xlsx');
Q1 = D(1:5,:);
m3 = D(:,2:5);
startDate = datenum('10-2006','mm-yyyy');
endDate = datenum('11-2099','mm-yyyy');
xdate = linspace(startDate,endDate,373); %number of months
figure
bar(xdate,m3);
datetick('x','mm-yyyy','keeplimits');
legend({'X1','X2','X3','X4'},'Location','Southeast');
Experiment to get the result you want.
  댓글 수: 4
Farshid R
Farshid R 2020년 12월 22일
Hi
Good time
I wrote this code but it gives an error
Please help me
thank you
n=100;
u1=[0,0]';
X1=[-4,-2,0]';
% p=data.PredictionHorizon;
a=0.9;h=0.9;
cp1=1;cp2=1;cp3=1;
% c1=0;c2=0;c3=0;
for j=1:n
c1(j)=(1-(1+a)/j)*cp1;
c2(j)=(1-(1+a)/j)*cp2;
c3(j)=(1-(1+a)/j)*cp3;
cp1=c1(j); cp2=c2(j); cp3=c3(j);
end
% initial conditions setting:
v1(1)=u1(1);
w1(1)=u1(2);
x1(1)=X1(1); y1(1)=X1(2); z1(1)=X1(3);
% calculation of phase portraits /numerical solution/:
for i=2:n
x1(i)=h*cos(z1(i-1))*v1(i-1) - memo(x1, c1, i);
y1(i)=h*sin(z1(i-1))*v1(i-1)-memo(y1, c2, i);
z1(i)=h*w1(i-1)-memo(z1, c3, i) ;
end
%%
function [yo] = memo(r, c, k)
%
temp = 0;
for j=1:k-1
temp = temp + c(j)*r(k-j);
end
yo = temp;
%
%%%%% error
Index exceeds the number of array elements (1).
Error in exocstrstateFcnCT1 (line 28)
x1(i)=h*cos(z1(i-1))*v1(i-1) - memo(x1, c1, i);
Star Strider
Star Strider 2020년 12월 23일
Farshid R —
Post this as a new Question. I will delete your Comment in a few hours.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by