How to fill array with previous values?
9 次查看(过去 30 天)
显示 更早的评论
Hello guys I have data which contains 2 columns and 600 rows. It basically contains inputs u and outputs y. And my question is how can I fill array 3x1 as follows:
z=[-u(n)-2*u(n-1)-u(n-2);y(n-2)-y(n-1);y(n)-y(n-1)];
I know that I have to make loop but my loop which is below isn't correct and I don't know how to fix it. So can you please help me?
N=length(y);
for n=1:N
for i=1:2
W(i) = y(n-i); %output
end
for i=1:2
V(i) = u(n-i+1); %input
end
z = [V';W'];
end
0 个评论
回答(2 个)
KSSV
2018-6-11
A = rand(600,2) ; % some random data
u = A(:,1) ; y = A(:,2) ;
n = 1:600 ;
z = zeros(600,3) ;
for n = 3:600
z(n,:) = [-u(n)-2*u(n-1)-u(n-2) y(n-2)-y(n-1) y(n)-y(n-1)];
end
z(1:2,:) = [] ;
Note, the above can be achieved without loop also.
2 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!