How to solve the for loop with row and column?

조회 수: 2 (최근 30일)
Arifur Rahman
Arifur Rahman 2018년 1월 26일
답변: Arifur Rahman 2018년 1월 26일
Hello. I have an equation which is in a for loop. The equation is like that,
for i=1:length(LIN.fK)
linecurrent(i)=(conj(uK(LIN.fK(i,1)))-conj(uK(LIN.tK(i,1))))*(conj(Grid.YKK(LIN.fK(i),LIN.tK(i))));
end
Where length(LIN.fK)=131
uK= voltage (69x96 matrix)
LIN.fK= from bus (131x1 matrix)
LIN.tK= to bus (131x1 matrix)
Grid.YKK= bus admittance matrix (69x69 matrix)
The thing is if I do this for loop it shows answers like 131 answers. However, my voltage(uK) is basically (69x96) matrix. so I want the result in such a way that it will show (131x96 matrix). Here 131 is number of lines, 96 means time steps. Could anyone help me regarding this?

답변 (2개)

Walter Roberson
Walter Roberson 2018년 1월 26일
"uK= voltage (69x96 matrix)"
But you have
uK(LIN.fK(i,1))
which indexes the 69x96 matrix with a single subscript. Is LIN.fK linear indices into the entire uK matrix?
I suspect you might have wanted
uK(LIN.fK(i,1), :)

Arifur Rahman
Arifur Rahman 2018년 1월 26일
Thank you so much, it works. I have to follow this thing in bigger equation as well.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by