clc
clear all
q=[2 31 6;2 31 7;2 31 6;2 31 6;2 31 6;2 31 6];
for i=1:6
if i>1
for j=1:i-1
if q(j,2)==q(i,2)
e = rand(10,1); % some matrix you want to sample from
idx5=randi(length(e)); % random index into x
q(j,2)=idx5
j=1;
end
end
end
end
I have matrix q ,I want to change the value in the second column in each row if the next value which means that the value in the next row is the same as the value in the previous row ex: row 1 the value in the second column is 31 row 2 the value in the second column is 31
so I want to change the second value which is 31 into a value by this random function when the value is changed ,the code suppose to start checking again starting from all previous values because maybe the new random value is matching again one of the previous values
the problem in the code that it is leaving the loop which is j=1:i-1 when i make j=1 again because i must start checking again all the values from the beginning
I checked by tracing that it is leaving the loop and it is start from loop for i=1:6 but it is suppose to stay in the second loop which is for j=1:i-1 till no previous random value is matching
so I want to make j=1 whenever the values is matching in the matrix,which mean starting the loop again from the beginning