How to randomly select values in one matrix and make them equal to values of a second matrix?

1 次查看(过去 30 天)
I have two separate matrices, X and Y, both containing 400 random numbers all between 1 and 20 (but X does not equal Y). I would like to create a loop that can randomly select values from X and set them equal to the value in the same position in Y, and for this loop to repeat until a certain condition is met. How would I go about setting up this loop?

回答(1 个)

the cyclist
the cyclist 2020-1-27
while ... % <---- condition goes here
idx = randi(400);
x(idx) = y(idx);
end

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by