How to implement data in to 2D array

If I generate 10000 random number and want to use 2D graphic to check its uniformity, but I don't know how to implement the data into the 100X100 array(other than using loops which costs a lot of time). Is there a simple instruction to do so? Thanks!

回答 (1 件)

James Garritano
James Garritano 2015 年 4 月 7 日
編集済み: James Garritano 2015 年 4 月 7 日

0 投票

Use reshape to convert a 1D array into a 2D arrays.
%%Reshape a column into a 2D array
myRandCol = rand(10000,1);
myRand2D = reshape(myRandCol,[100,100]);
%%Visualize
figure;imagesc(myRand2D);
Note: this example is slightly unrealistic, as it would make more sense to just generate the random number as a 2D matrix using
%%Generate Random Numbers as a 2D
myRand2D = rand(100,100)
However, that example isn't the in spirit of the question.

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2015 年 4 月 7 日

編集済み:

2015 年 4 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by