Select less value from matrix than proviusly selected
Show older comments
Hi,
I have a matrix 10x10 i want to select random two values. In the next step i want to select also two values, but these values must be less than the previously selected. I mean
1 step Value1 =2, value2 = 4
2 step value1 = 1, value2 =3
3 step value1 = 0, value2 = 0
The code to select the values in the first step is
% V1 is the first value
V1=zmiana(randi(numel(zmiana)));
randomIndex = randi(length(zmiana), 1)
selected_x_value = zmiana(randomIndex)
%V2 is the second value
V2=zmiana(randi(numel(zmiana)));
randomIndex = randi(length(zmiana), 1)
selected_y_value = zmiana(randomIndex)
But I really have no idea how to code the condition that the value in the next step must be less than the current value.
Please, advise.
Answers (1)
{A,B]=deal(zmiana);
while ~isempty(A) & ~isempty(B)
% V1 is the first value
V1=A(randi(numel(A)));
A(A>=V1)=[];
%V2 is the second value
V2=B(randi(numel(B)));
B(B>=V2)=[];
end
Categories
Find more on MATLAB Compiler SDK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!