To create a 5 by 3 matrix that starts at 1, increments by 1, and then doubles each column, you can use the following code:
main.m62 chars5 lines
The ones
function creates a 5 by 3 matrix filled with ones. The for
loop then iterates over each column of A
, and multiplies each element in that column by 2^(i-1)
, where i
is the current column index. The ^(i-1)
part means we are doubling the column for each iteration of the loop.
The resulting matrix A
will look like this:
main.m100 chars8 lines
gistlibby LogSnag