Info
此问题已关闭。 请重新打开它进行编辑或回答。
Extracting certain value from diagonal and perform some mathematics operation
1 次查看(过去 30 天)
显示 更早的评论
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
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!