Info
この質問は閉じられています。 編集または回答するには再度開いてください。
how to take whole matrix using loop index
1 回表示 (過去 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!