How do i assign a random element of an array a new value

2 次查看(过去 30 天)
I have an array maze=strings(size) where all the elements are "0" How did i randomly choose one of these elements and assign it "P"

回答(2 个)

madhan ravi
madhan ravi 2018-10-31
编辑:madhan ravi 2018-11-1
a=maze;
a(randi([1,numel(a)],1,1))='p'

Stephan
Stephan 2018-11-1
Hi,
try:
maze(randi(numel(maze))) = 'P';
Best regards
Stephan

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by