How can i change values in matrix in random fashion?
5 次查看(过去 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!