Convert a integer matrix to a red and blue colored matrix

조회 수: 2 (최근 30일)
Debadipto
Debadipto 2022년 9월 10일
댓글: Debadipto 2022년 9월 10일
I have the following matrix A = [-1 1 1; 1 -1 1; -1 -1 -1], I want to convert it to a colored matrix with cells corresponding to 1 colored red and -1 colored blue. Something like this:
How do I do that in matlab?

채택된 답변

Chunru
Chunru 2022년 9월 10일
A = [-1 1 1; 1 -1 1; -1 -1 -1]
A = 3×3
-1 1 1 1 -1 1 -1 -1 -1
imagesc(A);
% select a colormap
cmap = hsv(8); % based on hsv
cmap = cmap([5 1], :); % choose color 5 and 1
colormap(cmap);
colorbar

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by