Randomization... if not this then that
1 view (last 30 days)
Show older comments
Here is my code:
random = rand(1)
if random <(1/4)
tri1 = downtri
b1 = vertbaseq1
elseif random>=(1/4) && random<(2/4)
tri1 = uptri
b1 = vertbaseq1
elseif random>=(2/4) && random<(3/4)
tri1 = righttri
b1 = horzbaseq1
elseif random>=(3/4) && random<(4/4)
tri1 = lefttri
b1 = horzbaseq1
end
if random <(1/4)
tri2 = downtri
b2 = vertbaseq2
elseif random>=(1/4) && random<(2/4)
tri2 = uptri
b2 = vertbaseq2
elseif random>=(2/4) && random<(3/4)
tri2 = righttri
b2 = horzbaseq2
elseif random>=(3/4) && random<(4/4)
tri2 = lefttri
b2 = horzbaseq2
end
...
So what this code basically does is randomize between four different triangles at four different locations. The problem: it randomizes the same triangle to each location. I need the some code that says something like if triangle 1 (tri1) is an up triangle (uptri) then triangle 2 will be any triangle that isn't an up triangle.
any help would be greatly, greatly! appreciated, Brett
0 Comments
Accepted Answer
Image Analyst
on 25 Nov 2012
After your first if, have this instead of the second if:
if tri1 == uptri
% Triangle 2 can't be an uptriangle.
random = rand(1);
if random <(1/3)
tri2 = downtri
b2 = vertbaseq2
elseif random>=(1/3) && random<(2/3)
tri2 = righttri
b2 = horzbaseq2
else
tri2 = lefttri
b2 = horzbaseq2
end
else
% Triangle 2 can be anything.
if random <(1/4)
tri2 = downtri
b2 = vertbaseq2
elseif random>=(1/4) && random<(2/4)
tri2 = uptri
b2 = vertbaseq2
elseif random>=(2/4) && random<(3/4)
tri2 = righttri
b2 = horzbaseq2
elseif random>=(3/4) && random<(4/4)
tri2 = lefttri
b2 = horzbaseq2
end
end
4 Comments
Image Analyst
on 27 Nov 2012
You're welcome. Not bad for me just writing it and not even being able to run it or test it!
More Answers (0)
See Also
Categories
Find more on Random Number Generation 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!