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!