how can I fill a matrix with randomly -0.01 and 0.01
3 ビュー (過去 30 日間)
古いコメントを表示
I want to fill a matrix with only two diffrent numbers e.g. 0.01 and -0.01.
0 件のコメント
採用された回答
Stephen23
2017 年 3 月 23 日
編集済み: Stephen23
2017 年 3 月 23 日
>> V = [0.01,-0.01];
>> V(randi(numel(V),5,5))
ans =
-0.010000 0.010000 -0.010000 0.010000 0.010000
-0.010000 0.010000 0.010000 0.010000 -0.010000
-0.010000 -0.010000 0.010000 0.010000 -0.010000
0.010000 -0.010000 -0.010000 -0.010000 -0.010000
-0.010000 0.010000 -0.010000 0.010000 -0.010000
Although you could calculate the values from randi, this method using indexing has the advantage that the values are not calculated but are exactly those values that you define in V.
その他の回答 (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!