How to make 4 different colour on four different quadrant?
Afficher commentaires plus anciens
Hi, i have a question regarding the line colour. It was not equally or orderly distributed. It supposed to be a blue color on -45 degree to 45 degree, a red color starting from 45 degree to 135 degree, a black color from 135 degree to 225 degree. Last, the green color from 225 degree to 315 degree. Below are my coding.
for x = 1:9
for y = 1:9
Q=atan(Mnew(x,y));
if ((Q>=(-pi/4))&&(Q<(pi/4)))
plot([X(x,y) Xnew(x,y)],[Y(x,y) Ynew(x,y)],'b','LineWidth',3);
elseif ((Q>=(pi/4))&&(Q<(3*pi/4)))
plot([X(x,y) Xnew(x,y)],[Y(x,y) Ynew(x,y)],'r','LineWidth',3);
elseif ((Q>=(3*pi/4))&&(Q<(5*pi/4)))
plot([X(x,y) Xnew(x,y)],[Y(x,y) Ynew(x,y)],'k','LineWidth',3);
else
plot([X(x,y) Xnew(x,y)],[Y(x,y) Ynew(x,y)],'g','LineWidth',3);
end
hold on;
end
end
Mind to tell you that this is only half of my coding, and i hope anyone can check whether my coding for color distribution are correct or not.
Réponses (2)
Geoff Hayes
le 9 Nov 2015
0 votes
Nik - the documentation for atan indicates that calling this function returns values in the interval [-pi/2,pi/2]. You should probably use atan2 instead as it will return values in the interval of [-pi,pi]. With that in mind, you will need to adjust your checks for whether Q is less than 225 degrees and whether Q is less than 315 degrees (you will need to use the negative equivalents of -135 and -45 respectively).
2 commentaires
Nik Lutfi Jamal
le 11 Nov 2015
Modifié(e) : Geoff Hayes
le 11 Nov 2015
Geoff Hayes
le 11 Nov 2015
Nik - I don't observe any errors when I run the above code, so perhaps you have copied and pasted something different? As well, you need to use atan2 which requires two inputs (perhaps that is where the error is being generated?).
Thorsten
le 11 Nov 2015
0 votes
Use atan2 to get the four-quadrant inverse tangent.
Catégories
En savoir plus sur Entering Commands dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!