MATLAB: How to change a matrix as inserting zeroes both end sides

adiinserting zerosmatrix

I wanna make 'Az2' matrix 'Az' in the picture.
This is my code for doing that,
for o=2:1:zmax-1;
however, it's way slow… Can I have any other better coding for that as using vectorization? help me…

Best Answer

  • There's a gallery for that!
    az = rand(10,3);
    Az2 = full(gallery('tridiag',az(2:end,1),az(:,2),az(1:end-1,3)))
    doc gallery