How can we randomly assign the number we want to the machines that write 1 in the 1-0 matrix?

2 次查看(过去 30 天)
Hello everybody,
I need your help, We're solving a genetic algortihm questions. We have created a chromosome structure that assigns the numbers as 1-18. (9*138) We want to assign a random value between 1-10 to the numbers 1 in the 1-0 matrix we have created now. How can we code this in matlab?
Our code that we use;
for b = 2:9
N = 138;
j=1;
for i = 1:2:N
population(1,i) = int32(j);
population(b,i) = randi([1 10],1);
population(1,i+1) = int32(j);
population(b,i+1) = randi([11 18],1);
j = j+1;
end
end
Thanks in advance.

采纳的回答

Arif Hoq
Arif Hoq 2022-3-15
after for loop, try this
y=population;
y(y==1)=randi([2 10],1,1)
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by