How to call columns of matrices using 'for loop' ?

2 ビュー (過去 30 日間)
Khan
Khan 2021 年 4 月 15 日
コメント済み: Khan 2021 年 4 月 15 日
Hello,
I am new to MATLAB, can anyone tell me how can I use for loop for the following formulas?
Approx1=U(:,1)*S(1)*V(:,1)';
Approx2=U(:,1)*S(1)*V(:,1)'+ U(:,2)*S(2)*V(:,2)';
Approx3=U(:,1)*S(1)*V(:,1)'+ U(:,2)*S(2)*V(:,2)'+ UU(:,3)*S(3)*V(:,3)';
where U is 6 x 3, S is diagonal (3 x 3) and V is a 3 x 3 matrix. 1, 2 3 are being the columns of respective matrices.
Thank you
  8 件のコメント
Matt J
Matt J 2021 年 4 月 15 日
I want to Multiply first coulmn of U, S and V' matrices and then multiply second coulms of U, S and V' matrices
No, you can't because the columns of all these matrices have different lengths. You therefore cannot multiply their columns together.
Aren't you simply doing KL-transforms with different truncations? If so, that is what my answer below gives you, (and you should Accept-click it).
Khan
Khan 2021 年 4 月 15 日
Thank you

サインインしてコメントする。

採用された回答

Matt J
Matt J 2021 年 4 月 15 日
編集済み: Matt J 2021 年 4 月 15 日
for i=1:3
Approx{i}= U(:,1:i)*S(1:i,1:i)*V(:,1:i).';
end
  1 件のコメント
Khan
Khan 2021 年 4 月 15 日
編集済み: Khan 2021 年 4 月 15 日
dear, it is not working. actually in the first Approximation I want to Multiply, first coulmns of U, S and V' matrices. In the Second approximatrion, I want to Multiply first coulmn of U, S and V' matrices and then multiply second coulms of U, S and V' matrices, and then add them. Simillarly for the last approximation. I want to get three different approximations.

サインインしてコメントする。

その他の回答 (1 件)

David Hill
David Hill 2021 年 4 月 15 日
s=diag(S);
for i=1:3
Approx(:,:,i)=U(:,i)*V(:,i)'*s(i);%I am assuming this is what you want, s(i) being scalar along the diagonal
end
Approx=cumsum(Approx,3);
  6 件のコメント
David Hill
David Hill 2021 年 4 月 15 日
Hopefully you realize that S(1) is scalar and the first element in the diagonal matrix, S(2) will be zero, and S(3) will be zero. You are not multiplying by the column of S. The below produces the same result as expected.
for i=1:3
Approx(:,:,i)=U(:,i)*V(:,i)'*S(i);
end
Approx=cumsum(Approx,3);
Khan
Khan 2021 年 4 月 15 日
Thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by