How can i change values in matrix in random fashion?
3 ビュー (過去 30 日間)
古いコメントを表示
i have this matrix
p=[1 -1 -1 -1 -1 1 -1;
1 1 1 -1 -1 1 -1]
how can i randomly change the values at any two positions in this matrix.
note : random numbers are to be either 1 or -1
0 件のコメント
採用された回答
Cris LaPierre
2020 年 12 月 4 日
I'd use numel, and randi to identify 2 random points, and then, using linear indexing, multipy those 2 points by -1.
2 件のコメント
Steven Lord
2020 年 12 月 4 日
You probably want randperm not randi so you don't swap a point with itself. You don't want to reverse the polarity of the neutron flow if it's already had its polarity reversed; that would confuse the polarity!
その他の回答 (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!