change color of output graph
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anvinder Singh
am 2 Mär. 2016
Kommentiert: Anvinder Singh
am 2 Mär. 2016
I have a matlab plot (draw rectangle using matrix) but it shows the output in blue color whereas i want it in black color. How can i change it to black color ?
a = ones(256, 256, 3);
a(10:110,40:140)=0;
a(120:200,120:200)=0;
image(a)
I want the intensity of each square to be different actually. One should have intensity 100 and the other to be 300.
1 Kommentar
Akzeptierte Antwort
Geoff Hayes
am 2 Mär. 2016
Anvinder - the problem is with the following two lines
a(10:110,40:140)=0;
a(120:200,120:200)=0;
Remember, a is a 256x256x3 matrix. In the above, you are only setting the Red component to zero. These two lines would be equivalent to
a(10:110,40:140,1)=0;
a(120:200,120:200,1)=0;
If you want the squares to be black, then you need to set all three components (red, green, and blue) to zero using
a(10:110,40:140,:)=0;
a(120:200,120:200,:)=0;
When I try the above, the pale blue squares are replaced with black ones.
2 Kommentare
Weitere Antworten (2)
Image Analyst
am 2 Mär. 2016
You can use an indexed image if you don't want an RGB image and want values of 0, 100, and 300, and want the 100 and 300 both to show up as black. Just set up a colormap and apply it.
a = zeros(256, 256);
a(10:110,40:140) = 100;
a(120:200,120:200) = 300;
imshow(a, []);
cMap = [1,1,1;0,0,0]
colormap(cMap);
colorbar
caxis([0, 100]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173161/image.jpeg)
Muhammad Usman Saleem
am 2 Mär. 2016
Bearbeitet: Muhammad Usman Saleem
am 2 Mär. 2016
Accept this answer if satisfy your question
try
plot(array1,array2,'k')%k stand for black color
for more reading,
Siehe auch
Kategorien
Mehr zu Red finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!