Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to expand matrix in MATLAB

📅 2016-Mar-23 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Sometimes, you may want to increase the size of a matrix and pad the new locations with a value, like 0 or 1. Doing this is super easy in MATLAB, but the syntax will raise some eyebrows:

% m already exists, say of size 4x10
m(6,12) = 0;
% m is now of size 6x12
% Only the new locations are intialized with 1
% The old cells have their old values