Change one element in a row at a time with an uniform probability.
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello! I want to change one element in a row of my matrix at a time with uniform probability. Currenty my matrix of [50*50] chooses one element at a time from a set of [0, 0.1, 0. 0.2, 0.3, 0.4] with an uniform probability. With the following code. But in this more than one element changes at a time which does not satisfy the above condition. How to satisfy changing one element at a time with an uniform probablility?
% code
value_set = [range];
numvalues = 50;
x_star = value_set(randi(numel(value_set), 1, numvalues));
0 Commenti
Risposte (1)
BhaTTa
il 14 Ott 2024
Hey @Neje, i assume that in the given matrix you have to randomly chose a cell and replace that with a single element from the set of [0,0.1,0.2,0.3,0,4] with uniform probability
Please refer to the below code for the implementation.
value_set = [0, 0.1, 0.2, 0.3, 0.4];
matrix = zeros(50, 50);
num_updates = 100;
for i = 1:num_updates
row = randi(50);
col = randi(50);
new_value = value_set(randi(numel(value_set)));
% Update the selected element in the matrix
matrix(row, col) = new_value;
disp(matrix); % display each time so that we can see that only one cell is changing in each loop.
end
disp(matrix);
Hope it helps.
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!