How to solve the for loop with row and column?

1 次查看(过去 30 天)
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