Time series code not quite right, thoughts?
1 次查看(过去 30 天)
显示 更早的评论
AR(1) process:
T=10000;
e1 = randn(T/4,1);
e2 = randn(T/4,1);
e3 = randn(T/4,1);
e4 = randn(T/4,1);
e=[e1,e2,e3,e4];
a1=ones(T/4,1);
a2=ones(T/4,1);
a3=ones(T/4,1);
a4=ones(T/4,1);
a=[a1,a2,a3,a4];
rho = 1.5;
time = 1:T-1; % for plotting purposes only
Y(1) = 0; %Initial condition
for i=2:T
Y(i,1) = a + e(i) + rho*Y(i-1,1);
end
plot(time, Y)
_
Am getting the error: Subscripted assignment dimension mismatch. How should I correct my for loop to generate the attached?
回答(2 个)
Jae Song
2015-9-21
I don't know if this is the plot you were trying to generate. I made the following correction to make the plot to work.
1) a and e seem same size; so I made a and e using the same index. 2) y seems an array 3) plot: time and y should have same size.
T=10000;
e1 = randn(T/4,1); e2 = randn(T/4,1); e3 = randn(T/4,1); e4 = randn(T/4,1);
e=[e1,e2,e3,e4];
a1=ones(T/4,1); a2=ones(T/4,1); a3=ones(T/4,1); a4=ones(T/4,1);
a=[a1,a2,a3,a4];
rho = 1.5; time = 1:T-1; % for plotting purposes only
Y(1) = 0; %Initial condition
for i=2:T
Y(i) = a(i) + e(i) + rho*Y(i-1);
end
plot(time, Y(2:end))
1 个评论
Joseph Cheng
2015-9-22
the rho of 1.5 really makes it out of hand. as the e(i) cannot compensate for a 150% change from the previous number. are you sure you want a rho of 1.5?
Joseph Cheng
2015-9-22
are you looking to something more like this?
T=10000;
%why generate e it 4 times when randn can generate it for you
e = randn(T/4,4);
%generate some offset within the 4 different sections
a=[randi(10,1,4)];
a = repmat(a,T/4,1);
rho = 1.5/100; %rho is probably in percentage
time = 1:T; % for plotting purposes only
%preallocate Y
Y = zeros(size(a));
%generate a new initial condition for each section or keep Y =0;'
Y(1,:) = randi(10,1,4); %Initial condition
%perform this if each segment isn't influenced by each other
for i=2:T/4
Y(i,:) = a(i,:) + e(i,:) + rho*Y(i-1,:);
end
% perform this if each segment is influenced by their predecessor.
for i=2:T
Y(i) = a(i) + e(i) + rho*Y(i-1);
end
plot(time, Y(:))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate and Multistage Filters 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!