how would I create a 6x6 matrix with evenly distributed values from -10 to 10?

6 ビュー (過去 30 日間)
Jonathan Trencheny
Jonathan Trencheny 2016 年 2 月 13 日
回答済み: Walter Roberson 2016 年 2 月 13 日
I know a long way, by typing out the exact values, I was just curious as to if there was a more efficient way.

採用された回答

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

その他の回答 (1 件)

Walter Roberson
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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by