I got a K (5x5) matrix all zeros K1 (3x3) is associated with 1,2,3 K2 (3x3) is associated with 3,4,5
I Need to add K1 and K2 in a for loop to make a 5x5 matrix

댓글 수: 4

Do you mean the equivalent of
result = zeros(5,5);
result(1:3, 1:3) = K1;
result(3:5,3:5) = result(3:5,3:5) + K2;
?
Ibrahim Mahmood Shah
Ibrahim Mahmood Shah 2017년 3월 6일
I guess, very similar to that ...what if i have K1..k2..k3..till k100
Walter Roberson
Walter Roberson 2017년 3월 6일
If you have K1..k2..k3..till k100 then you rewrite your code so that you do not have those.
Stephen23
Stephen23 2017년 3월 6일
Read these:
And this quote from the MATLAB documentation: "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended"
Then use indexing instead of dynamic variable names: indexing is simple, fast, efficient, and much less buggy.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2017년 3월 6일

댓글:

2017년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by