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?

1 回表示 (過去 30 日間)
Jesus Antonio Perez
Jesus Antonio Perez 2018 年 1 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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