|
Further Examples: PadRight
Padding a list
This makes a list of length by padding to the right with x's.
In[1]:= 
Out[1]= 
Using gives padding on the left.
In[2]:= 
Out[2]= 
Using an empty list, you can see how a cyclic padding ends on the first element of the padding.
In[3]:= 
Out[3]= 
Now the nonempty list is superimposed on the padding.
In[4]:= 
Out[4]= 
Here the list is padded on the left by elements.
In[5]:= 
Out[5]= 
And here the first elements of the list are dropped.
In[6]:= 
Out[6]= 
This treats the list as cyclic.
In[7]:= 
Out[7]= 
This has the same effect.
In[8]:= 
Out[8]= 
Padding a matrix
This pads a matrix to give rows and columns.
In[9]:= 
Out[9]//MatrixForm= 
This does the same thing, but uses a block to provide the padding.
In[10]:= 
Out[10]//MatrixForm= 
This shifts the matrix down row and to the right columns.
In[11]:= 
Out[11]//MatrixForm= 
Padding graphics
Here is a nested list.
In[12]:= 
Out[12]//MatrixForm= 
This represents the list using Raster. (Raster starts from the lower-left corner so the picture seems upside-down.)
In[13]:= 

Here the list is padded.
In[14]:= 
Out[14]//MatrixForm= 
In[15]:= 

Here are two different paddings.
In[16]:= 
Out[16]//MatrixForm= 
In[17]:= 

In[18]:= 
Out[18]//MatrixForm= 
In[19]:= 

Making a Block Diagonal Matrix
This defines the function BlockDiagonalMatrix which creates a block diagonal matrix from a list of matrices.
In[20]:= 
Here are four matrices.
In[21]:= 
Out[21]//MatrixForm= 
In[22]:= 
Out[22]//MatrixForm= 
In[23]:= 
Out[23]//MatrixForm= 
In[24]:= 
Out[24]//MatrixForm= 
Here is the block diagonal matrix constructed from the four matrices.
In[25]:= 
Out[25]//MatrixForm= 
In[26]:= 
|