How do I convert a 2X2 matrix to 4X4 matrix in MATLAB?

后端 未结 7 912
無奈伤痛
無奈伤痛 2020-12-03 23:26

I need some help in converting a 2X2 matrix to a 4X4 matrix in the following manner:

A = [2 6;
     8 4]

should become:

B =         


        
相关标签:
7条回答
  • 2020-12-04 00:27

    This works:

    A = [2 6; 8 4];
    [X,Y] = meshgrid(1:2);
    [XI,YI] = meshgrid(0.5:0.5:2);
    B = interp2(X,Y,A,XI,YI,'nearest');
    

    This is just two-dimensional nearest-neighbor interpolation of A(x,y) from x,y ∈ {1,2} to x,y ∈ {0.5, 1, 1.5, 2}.

    Edit: Springboarding off of Jason S and Martijn's solutions, I think this is probably the shortest and clearest solution:

    A = [2 6; 8 4];
    B = A([1 1 2 2], [1 1 2 2]);
    
    0 讨论(0)
提交回复
热议问题