Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

We are trying to make a board, using a matrix with numbers 0, 1 and 2. How can we specified the color of each number in the board using image?

조회 수: 4 (최근 30일)
We are trying to make a board, using a matrix with numbers 0, 1 and 2. How can we specified the color of each number in the board using image?

답변 (1개)

Matt Sprague
Matt Sprague 2018년 1월 12일
You can treat the matrix created as an indexed image and use ind2rgb after defining a custom colormap with 3 levels (one for each value). A small example is shown below for setting the value of 0 to red, 1 to green and 2 to blue.
num = randi(3,100)-1;%randi generates integers from 1-3.
map = [1 0 0
0 1 0
0 0 1];
rgbImage = ind2rgb(num+1, map);
imagesc(rgbImage)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by