How to fill array with previous values?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
KSSV
am 11 Jun. 2018
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 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!