필터 지우기
필터 지우기

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