필터 지우기
필터 지우기

How to display matrix as an image ?

조회 수: 44 (최근 30일)
Suresh Dahal
Suresh Dahal 2017년 8월 22일
편집: Adam 2017년 8월 22일
I have a diagonal matrix A of 4x4 and I want to display this as an image, how am I supposed to do that? I tried using imshow(A) and it does not work, please help.
  댓글 수: 2
Baptiste Ottino
Baptiste Ottino 2017년 8월 22일
Could you be more precise please? What type is your matrix? What error does imshow return? imshow should be the right function here, so the problem is elsewhere.
Adam
Adam 2017년 8월 22일
편집: Adam 2017년 8월 22일
figure; imagesc(A)

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

답변 (1개)

Reen
Reen 2017년 8월 22일
Try using:
image(A)
That will display the image like a heatmap with each entry being a square. If you want to specify the color of each square, you'll have to use a 3 dimensional array. For example if you use something like:
A(:,:,1) = [255 0 255 0; 0 255 0 255; 255 0 255 0; 0 255 0 255];
A(:,:,2) = [255 0 255 0; 0 255 0 255; 255 0 255 0; 0 255 0 255];
A(:,:,3) = [255 0 255 0; 0 255 0 255; 255 0 255 0; 0 255 0 255];
% A(1,1,:) is the rgb color vector, so white for A(1,1,:) = [255 255 255] and black for A(1,2,:) = [0 0 0]
image(A)
you'll get something that looks like a checkerboard.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by