How to fill array with previous values?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
KSSV
il 11 Giu 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 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!