Help with Matlab code
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone!
I am looking at a matlab code which I need help in understanding. Itt is set up in a matrix form, but I have difficulty understanding the full function it represents.
Static variables:
MS1 = eye(16,16); %system for {p,p*,mc,mc*,l,l*,y,y*,yh,yh*,yf,yf*,rk,rk*,r,r*}
Dynamic:
MD1 = eye(26); %system for x={ph,ph*,pf,pf*,w,w*,c,c*,i,i*,e,k,k*,b,r_,r*_,ph_,ph*_,pf_,pf*_,w_,w*_,e_,a,a*,psi}
MD2 = zeros(26,26); %MD1*x_{t+1} = MD2*x_{t}+MD3*epsilon_{t+1}
MD3 = zeros(26,5); %epsilon={em,em*,ea,ea*,epsi} - current {em,em*}, but future {ea,ea*,epsi}!
This code snippet below is an example from the dynamic part which I struggle to understand. I have the paper without the exact functions. So based on this I am trying to understand and set up a function from it.
I would highly appreciate it if someone could help me understand what it means. For instance MD2(7,:): I am not sure what ":" means.
MD1(7,7) = sigma; %c
MD1(7,:) = MD1(7,:)+MS(1,:);
MD2(7,7) = sigma;
MD2(7,:) = MD2(7,:)+MS(1,:)+MS(15,:);
MD3(7,:) = MSin(15,:);
0 commentaires
Réponses (1)
Image Analyst
le 6 Avr 2025
The colon, :, means "all" so
MD2(7,:) = MD2(7,:)+MS(1,:)+MS(15,:);
means set all columns in row 7 of MD2 to be what they originally were (that's MD2(7,:)) PLUS the sum of all columns in rows 1 and 15 of MS added together (that's the MS(1,:)+MS(15,:) part).
So in other words, to do in a for loop instead of vectorized:
for col = 1 : size(MD2, 2)
MD2(7, col) = MD2(7, col) + MS(1,col) + MS(15, col);
end
To learn other fundamental concepts, invest 2 hours of your time here:
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
