How do I generate a 5x5 plot using pcolor?

Good evening!
I have a problem: I want to produce a 5x5 grid image plot of black and white cells. The following code only produces a 4x4 grid of cells, even though the matrix A is a 5x5. Can someone please identify what I'm doing wrong?
clear;clc
A = [0 0 0 0 0;
0 0 0 0 0;
0 0 1 1 0;
0 0 0 0 0;
0 0 0 0 0];
mymap = [1 1 1;
0 0 0];
pcolor(A)
colormap(mymap)
axis square

回答 (1 件)

Honglei Chen
Honglei Chen 2012 年 4 月 2 日

0 投票

Just use
A =[0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 0 1 1 0;
0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 0 0 0 0];
pcolor uses the entries in A as the four corners of the cell, as explained in the doc

3 件のコメント

Joe M
Joe M 2012 年 4 月 2 日
Good evening, Honglei! Thank you for your response. I guess I should be more specific: Can I use pcolor, with the A matrix as written, to generate a 5x5 grid plot? If not, then what do I use to generate that plot? I'm limited to using the A as a 5x5 and not as an augmented 6x6.
Honglei Chen
Honglei Chen 2012 年 4 月 2 日
Do you have to use pcolor? How about imagesc? It does not have the grid lines but I don't know if that's critical to you.
Walter Roberson
Walter Roberson 2012 年 4 月 2 日
imagesc() and turn the axis grid on if you need it.
Honglei is correct, pcolor _always_ outputs a smaller color matrix than its input matrix. imagesc() and image() and imshow() output the same size grid as their input. imagesc() always automatically scales the data to the available output color range, and imshow() has a simple option to do that, but image() does not scale the data.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

質問済み:

2012 年 4 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by