Info
此问题已关闭。 请重新打开它进行编辑或回答。
how to take whole matrix using loop index
2 次查看(过去 30 天)
显示 更早的评论
whilw solving alernate optimzation problem, i am having issue with takiing whole matrix using loop. i have two matrices for example W=6*6 and theta1=6*6,
maximize(real(trace( theta1(i)*Hs*W(i)*Hs' )))
now i have to take whole matrices not elements like W and theta1 should be 6*6.
kindly some one help i am stuck here.
0 个评论
回答(1 个)
Vinicius Pereira Mateus Borges
2020-9-19
I am not sure if I understand the question. Please attach some of your data and code as an example if the following does not help:
1) Instead of using a for loop, can you not just do element-wise multiplication between the matrices?
maximize(real(trace( theta1 .* Hs .* W * Hs' ))) % assuming Hs is a constant
2) If Hs is a changing part of a for loop, then you two options:
% double indexing with i and j for rows and colums
for i = 1:6
for j = 1:6
maximize(real(trace( theta1(i,j)*Hs*W(i,j)*Hs' )))
end
end
% using linear indexing (so counting between 1:36)
for i = 1:36 % works for a 6 by 6 matrix, but you may want to soft code this
maximize(real(trace( theta1(i)*Hs*W(i)*Hs' )))
end
You may want to look at how linear indexing works before using the second option. For instance, in a 6-by-6 matrix, theta1(7) would be the first element of the second row (same as theta1(1,2)).
1 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!