Matrix with values dependent on row and column.

1 次查看(过去 30 天)
How would I construct a 10 by 10 matrix whose values are defined by the sum of the value's row and column ?

采纳的回答

Star Strider
Star Strider 2019-4-6
One approach:
[rm,cm] = ndgrid(1:10);
rv = rm(:);
cv = cm(:);
el = rv + cv;
R = reshape(el, 10, 10) % Desired Result
producing:
R =
2 3 4 5 6 7 8 9 10 11
3 4 5 6 7 8 9 10 11 12
4 5 6 7 8 9 10 11 12 13
5 6 7 8 9 10 11 12 13 14
6 7 8 9 10 11 12 13 14 15
7 8 9 10 11 12 13 14 15 16
8 9 10 11 12 13 14 15 16 17
9 10 11 12 13 14 15 16 17 18
10 11 12 13 14 15 16 17 18 19
11 12 13 14 15 16 17 18 19 20
This could be written in two lines, of course. I wrote it this way to demonstrate how the code works.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by