Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to expand matrix in MATLAB

📅 2016-Mar-23 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ matlab, matrix ⬩ 📚 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

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧