Basics-

How to create a matrix M1 in which each entry is the sum of the row index number and the column index number???
second question
How to create a matrix X that is equal to the matrix product of a and c ( which are previously created) =[1 1 1;0 1 1;0 0 1]

回答(2 个)

Matt Fig
Matt Fig 2011-1-21

0 个投票

% Create an m-by-n matrix where each element is sum of row and col position.
D = ones(m,n);
[I,J] = find(D);
D(:) = I+J
Another way too:
D = ones(m,n);
D(:) = ceil((1:m*n)/m) + rem((1:m*n)-1,m) + 1
Your second question is not clear. Elaborate.
Walter Roberson
Walter Roberson 2011-1-21

0 个投票

I am not sure what the matrices "a" and "c" represent, but matrix multiplication between the two would be X = a*c .
For the matrix M1:
m = 5; n = 6; mn = max(m,n);
t = hankel(2:mn+1) + fliplr(flipud(hankel([2*mn:-1:mn+2 0])));
M1 = t(1:m,1:n);
... Not that Matt's answer won't work fine, but sometimes it is nice to know about alternatives.
But the cleaner version of what Matt proposed is:
M1 = bsxfun(@plus,(1:m).',1:n);

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

标签

提问:

2011-1-21

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by