# Inconsistency in reassigning a variable for color

1 view (last 30 days)
Brett on 24 Jan 2013
Hi Matlab community, so here is my code:
randcol = randperm(4);
q3col = randcol(1);
q1col = randcol(2);
q4col = randcol(3);
q2col = randcol(4);
if q3col == 1;
colour1 = c1;
elseif q3col == 2;
colour1 = c2;
elseif q3col == 3;
colour1 = c3;
elseif q3col == 4;
colour1 = c4;
end
if q1col == 1;
colour2 = c1;
elseif q1col == 2;
colour2 = c2;
elseif q1col == 3;
colour2 = c3;
elseif q1col == 4;
colour2 = c4;
end
if q4col == 1;
colour3 = c1;
elseif q4col == 2;
colour3 = c2;
elseif q4col == 3;
colour3 = c3;
elseif q4col == 4;
colour3 = c4;
end
if q2col == 1;
colour4 = c1;
elseif q2col == 2;
colour4 = c2;
elseif q2col == 3;
colour4 = c3;
elseif q2col == 4;
colour4 = c4;
end
THEN
randloc = randperm(4);
locq1 = randloc(1);
locq2 = randloc(2);
locq3 = randloc(3);
locq4 = randloc(4);
if locq3 == 3 ;
tarloc1 = [0 80;0 -80;-80 0] + repmat([rx, by], 3, 1); %Q3
tarloc2 = [0 80;0 -80;80 0] + repmat([rx, by], 3, 1); %Q3
colour1 = nc;
elseif locq1 == 1;
tarloc1 = [0 80;0 -80;-80 0]+ repmat([lx, ty], 3, 1); %Q1
tarloc2 = [0 80;0 -80;80 0] + repmat([lx, ty], 3, 1); %Q1
colour2 = nc;
elseif locq4 == 4;
tarloc1 = [0 80;0 -80;-80 0] + repmat([lx, by], 3, 1); %Q4
tarloc2 = [0 80;0 -80;80 0] + repmat([lx, by], 3, 1); %Q4
colour3 = nc;
elseif locq2 == 2;
tarloc1 = [0 80;0 -80;-80 0] + repmat([rx, ty], 3, 1); %Q2
tarloc2 = [0 80;0 -80;80 0] + repmat([rx, ty], 3, 1); %Q2
colour4 = nc;
end
So, the first part of the code randomizes four different colors. The second part turns one of the colors to black(nc) if a diamond appears at that location. Here is my problem, sometimes this works, other times it doesn't. I think the problem is sometimes reassigning colour1 to nc does not work, but I'm not sure why. Is there anything I can do to make reassigning the variable work consistently?
Thanks, Brett :)

Brett on 25 Jan 2013
Resolved by doing it a completely different way.