Ältere Kommentare anzeigen
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]
Antworten (2)
Matt Fig
am 21 Jan. 2011
% 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
am 21 Jan. 2011
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);
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!