how to take whole matrix using loop index
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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.
Respuestas (1)
Vinicius Pereira Mateus Borges
el 19 de Sept. de 2020
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 comentario
wasif
el 19 de Sept. de 2020
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!