How to expand matrix in MATLAB

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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s