Coloured checkerboard in Matlab

조회 수: 5 (최근 30일)
Maheen Siddiqui
Maheen Siddiqui 2017년 7월 17일
댓글: Maheen Siddiqui 2017년 7월 18일
I'm using the Matlab checkerboard function to create a checkerboard. I'm interested in having the checkerboard as stripes (rather than checks) which I have figured out. I also want to change the colour of the stripes so that it's red and white or red and pink rather than black and white. I don't understand how to do this.
In the Matlab checkerboard function, black is defined as zeros(n) where n is the size and because the colour code for black in Matlab is [0 0 0], this works. But I don't get how to set this for it to produce red coloured tiles or stripes.
I have tried
red = repmat([1 0 0], 81,27)
to get red stripes for a checkerboard that I want with 81 squares. This produces an 81 x 81 matrix that looks like:
1 0 0 1 0 0 1 0 0 .... 1 0 0
1 0 0 1 0 0 1 0 0 .... 1 0 0
1 0 0 1 0 0 1 0 0 .... 1 0 0
.
.
.
1 0 0 1 0 0 1 0 0 .... 1 0 0
And it isn't red, it's just black and white stripes of varying thickness.
Can anyone help?!

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 17일
red = repmat(uint8([1 0 0]), 81,27);
cmap = [0 0 0; 1 0 0];
image(red);
colormap(cmap);
  댓글 수: 5
Maheen Siddiqui
Maheen Siddiqui 2017년 7월 18일
The attached is what I end up with when I run this. That's the problem you see, it's not displaying as I'd like it to. There are solid red blocks in the middle instead of a consistent pattern across the board... Do you know why this may be happening?
Maheen Siddiqui
Maheen Siddiqui 2017년 7월 18일
Actually sorry! I had written some very stupid lines in the code that I forgot to comment out. Correcting them gives me the desired result. Thanks very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 White에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by