Help with Matlab code

조회 수: 8 (최근 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