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

조회 수: 13 (최근 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.

채택된 답변

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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by