MATLAB: How to add matrices with different dimensions

add different matrices

hello, I want the shortest way to add matrices with different dimensions. I know the easiest way but it is not appropriate for big matrices like 10*10 or bigger please see the picture to understand what I mean Sorry there was a problem with the picture. I provide an example. I hope it is clear now.

Best Answer

  • That makes more sense now. you can do something like this.
    K1(1:length(k1),1:length(k1))= k1;
    k2pattern= [5:6 1:2];
    K2(k2pattern,k2pattern) = k2;
    not the most efficient way nor did i supply how to vary depending on the size of the matrix. However this was <5 min of thinking without knowing what to with k2 for larger sizes. Just substitute the k2pattern with what its column labeling.