フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Extracting certain value from diagonal and perform some mathematics operation

1 回表示 (過去 30 日間)
KIEN WEI LAI
KIEN WEI LAI 2019 年 11 月 25 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi everyone, I have a matrix with the dimension of 2*NW*NL. I want to get the certain element from the diagonal of the matrix to perform some mathematics operation. The element I want to get from the diagonal is 3+(2*NW)i. This means that if I put NW=5 and NL=4, it should be have a loop counting NL from 0 until 4, the element I want to get from the diagonal is at 3rd, 13th, 23rd and 33rd. These element I get from the diagonal of matrix needed to be done for some mathematical operation. However, the code below get the result where all the diagonal of the matrix has perform the mathematics operation, and the mathematical operation is not as same as I mention later. The mathematics operation is +3, +2, +1, -3, -2 and -1. Anyone can help me to edit my code? Thanks. The following is my code:
NW = 5;
NL = 4;
i = NL-1;
a = 3+(2*NW);
c = a*i;
z = 4;
for d = 0:i
for b = 1:c
if z == 1
H(b,b) = H(b,b) + 3;
elseif z == 2
H(b,b) = H(b,b) + 2;
elseif z == 3
H(b,b) = H(b,b) + 1;
elseif z == 4
H(b,b) = H(b,b) - 3;
elseif z == 5
H(b,b) = H(b,b) - 2;
elseif z == 6
H(b,b) = H(b,b) - 1;
end
end
end
  1 件のコメント
Darshan Sen
Darshan Sen 2019 年 11 月 25 日
Hello Kien Wei Lai. I'd really like to help you out but I'm not sure I completely understand your question. It would be wonderful if you could kindly fill up an example matrix H (I presume that's the matrix you're referring to) with some values and show us what you want the expected result to be after the desired operation has been performed. I hope that would be more understandable. Thank you. :)

回答 (0 件)

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by