Help with Matlab code

7 Ansichten (letzte 30 Tage)
Molly
Molly am 6 Apr. 2025
Bearbeitet: Molly am 6 Apr. 2025
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,:);

Antworten (1)

Image Analyst
Image Analyst am 6 Apr. 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:
  1 Kommentar
Molly
Molly am 6 Apr. 2025
Bearbeitet: Molly am 6 Apr. 2025
Thank you so much, I was just watching a few concepts with practical questions, but I will jump straight to the one you sent me now. And give an update on my work.
Thank you!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices 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!

Translated by