how would I create a 6x6 matrix with evenly distributed values from -10 to 10?
22 次查看(过去 30 天)
显示 更早的评论
I know a long way, by typing out the exact values, I was just curious as to if there was a more efficient way.
0 个评论
采纳的回答
Jon
2016-2-13
Not entirely sure how you want the values distributed (by row or column), but see if this helps:
Msize = 6;
n = Msize^2;
values = linspace(-10,10,n);
matrix = reshape(values,Msize,Msize);
0 个评论
更多回答(1 个)
Walter Roberson
2016-2-13
randi([-10,10],6,6)
If you want integer values.
rand(6,6)*20-10
if you want continuous values
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!