calling a matrix with indexing

20 views (last 30 days)
Mei Li
Mei Li on 20 Feb 2014
Answered: ag on 2 Dec 2024
Dear all, I am not sure whether it is called inequality addition (for the sigma part) or anything, but I have to call the matrix to solve the equation. Here is the formula:
here is the variable: K=2; k=1:K; l=1:K, except l=k. for example:
Do you have any idea to generally write it in matlab? maybe using for or while function?
Thank you

Answers (1)

ag
ag on 2 Dec 2024
Hi Mei,
To implement the given formula, you can use a nested "for" loop as shown in the below code snippet:
% Compute Q_k for each k
for k = 1:K
sum_term = 0;
for l = 1:K
if l ~= k
% Compute the term for l != k
term = (P(l) / d(k)) * H(k, l, :) * F(l, :)' * F(l, :) * H(k, l, :)';
sum_term = sum_term + term;
end
end
Q(k) = sum_term;
end
For more details, please refer to the following MathWorks documentations:
Hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!