Colormap Question for script requirements? - Homework

1 回表示 (過去 30 日間)
Nora
Nora 2013 年 11 月 18 日
コメント済み: Nora 2013 年 11 月 19 日
I am trying to make two colormaps. Both will be using white and black colors only. It is a 50 x 50 matrix image where each element is randomly either white or black. However, the second image has the colors reversed (so all white is black and vice versa). This is my script I have.
subplot(1,2,1);
cm = [0 0 0;1 1 1];
colormap(cm);
mat = randi(2,50);
image(mat);
title('Yin');
subplot(1,2,2);
cm2 = [1 1 1;0 0 0];
colormap(cm2);
image(mat);
title('Yang');
The only problem is that I don't know where to have the second image switch colors from the first image???

採用された回答

Image Analyst
Image Analyst 2013 年 11 月 18 日
Try this:
subplot(1,2,1);
matrix1 = uint8(randi(2,50) - 1);
imshow(matrix1, []);
title('Yin', 'FontSize', 50);
subplot(1,2,2);
matrix2 = 1 - matrix1;
imshow(matrix2, []);
title('Yang', 'FontSize', 50);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
  2 件のコメント
Nora
Nora 2013 年 11 月 19 日
That works! Just curious though, how would I keep the x and y axis numbers/scale?
Nora
Nora 2013 年 11 月 19 日
What I mean is, is there a way to do the above using colormap?
I have this script but the second image isn't working.
subplot(1,2,1);
cm = [1 1 1; 0 0 0];
colormap(cm);
mat = randi(2,50);
image(mat);
title('Yin');
subplot(1,2,2);
cm2 = [1 1 1; 0 0 0];
colormap(cm2);
mat2 = mat - 1;
image(mat2);
title('Yang');

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBlue についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by