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]

Réponses (2)

Matt Fig
Matt Fig le 21 Jan 2011

0 votes

% 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 le 21 Jan 2011

0 votes

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);

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Tags

Question posée :

le 21 Jan 2011

Community Treasure Hunt

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

Start Hunting!

Translated by