how to make the matrix 4 by 4 with the value of 10

7 次查看(过去 30 天)
hello i want to make the matrix with the dimension of 4 by 4 and each element have the value of 10 can u help me with that?

回答(2 个)

Stephen23
Stephen23 2015-5-16
编辑:Stephen23 2015-5-21
Method one:
A = 10 * ones(4)
Method two:
A(1:4,1:4) = 10
Method three:
A = 10 + zeros(4)
Method four:
A = repmat(10,4,4)
Method five:
A = [10,10,10,10;10,10,10,10;10,10,10,10;10,10,10,10]
Method six:
A(4,4) = 0;
A(:) = 10
Method seven:
A = bsxfun(@plus,[1,1,1,1],[9;9;9;9])
Method eight:
A = [10;10;10;10]*[1,1,1,1]
Method nine:
A = 10.^ones(4)
Method ten:
A = toeplitz([10,10,10,10],[10,10,10,10])
Method eleven:
A = round(real(ones(4)^2.660965))
Method twelve:
A = mod(10,zeros(4))
Method thirteen:
A = accumarray([1,1],10,[4,4],@sum,10)
  2 个评论
Stephen23
Stephen23 2015-5-21
编辑:Stephen23 2015-5-21
Already there as Method Three :)
I avoided 9+ones(4) though, for being basically the same thing.

请先登录,再进行评论。


Star Strider
Star Strider 2015-5-19
And still another possibility:
A = randi([10 10], 4, 4);
  3 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by