How to make 4 different colour on four different quadrant?
Mostrar comentarios más antiguos
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.
Respuestas (2)
Geoff Hayes
el 9 de Nov. de 2015
0 votos
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 comentarios
Nik Lutfi Jamal
el 11 de Nov. de 2015
Editada: Geoff Hayes
el 11 de Nov. de 2015
Geoff Hayes
el 11 de Nov. de 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
el 11 de Nov. de 2015
0 votos
Use atan2 to get the four-quadrant inverse tangent.
Categorías
Más información sobre Data Exploration en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!