Help with Matlab code

7 次查看(过去 30 天)
Molly
Molly 2025-4-6
编辑: Molly 2025-4-6
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,:);

回答(1 个)

Image Analyst
Image Analyst 2025-4-6
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 个评论
Molly
Molly 2025-4-6
编辑:Molly 2025-4-6
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!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by