Nodal admittance matrix using for loop and if statement
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to ask how can I get the matrix Y if I have the value of y1, y12, y13, y23,...,etc.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157175/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157176/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157178/image.jpeg)
I have coding as below, but it dose not work. Who can help me?
B_matrix =[0 2.5000 0 1.6667 5.0000 0; -2.5000 0 5.0000 2.5000 0 0;0 -5.0000 0 0 5.0000 0; -1.6667 -2.5000 0 0 0 0; -5.0000 0 -5.0000 0 0 0; 0 0 0 0 0 0]
Y=zeros(6,6);
for m=1:6
for n=1:6
if m==n
for (k=1:6) & (k ~ = m)
Y(m,n)=B_matrix(m,n)+B_matrix(m,k);
else
Y(m,n)=-B_matrix(m,n);
end
end
end
end
Y
댓글 수: 0
채택된 답변
Andrei Bobrov
2016년 10월 16일
Y = diag(sum(B_matrix,2)) - (~eye(size(B_matrix))).*B_matrix;
댓글 수: 2
Andrei Bobrov
2016년 10월 16일
aB = abs(B_matrix);
Y = diag(sum(aB,2)) - (~eye(size(B_matrix))).*aB;
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!